The repository contains implementations of various data structures in C. Here’s what you’ll likely find:
- Linked Lists: A linear data structure where each element points to the next.
- Stacks: A Last-In-First-Out (LIFO) data structure.
- Queues: A First-In-First-Out (FIFO) data structure.
- Trees: Hierarchical data structures like binary trees.
- Graphs: Data structures for representing networks.
Since the repository contains multiple files, each file likely represents a specific data structure or algorithm. Here’s how you can run the code:
- Open your terminal and run:
git clone https://github.com/yossef-ashraf/Data-Structures.git
- Go to the downloaded folder:
cd Data-Structures
- List the files in the repository to see what’s available:
You’ll likely see files like
ls
linked_list.c,stack.c,queue.c, etc.
-
For example, if you want to run the Linked List implementation:
- Compile the file:
gcc linked_list.c -o linked_list
- Run the executable:
./linked_list
- Compile the file:
-
Repeat the same process for other files (e.g.,
stack.c,queue.c, etc.).
Let’s assume the linked_list.c file contains the following code:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
void printList(struct Node* node) {
while (node != NULL) {
printf("%d -> ", node->data);
node = node->next;
}
printf("NULL\n");
}
int main() {
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;
head = (struct Node*)malloc(sizeof(struct Node));
second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));
head->data = 1;
head->next = second;
second->data = 2;
second->next = third;
third->data = 3;
third->next = NULL;
printList(head);
return 0;
}- Compile the code:
gcc linked_list.c -o linked_list
- Run the executable:
./linked_list
1 -> 2 -> 3 -> NULL
Here’s a brief explanation of what each file in the repository might do:
-
list.c:- Implements a singly linked list with basic operations like insertion, deletion, and traversal.
-
stack.c:- Implements a stack data structure with operations like
push,pop, andpeek.
- Implements a stack data structure with operations like
-
queue.c:- Implements a queue data structure with operations like
enqueue,dequeue, andpeek.
- Implements a queue data structure with operations like
-
tree.c:- Implements a binary tree with operations like insertion, deletion, and traversal (e.g., in-order, pre-order, post-order).
-
graph.c:- Implements a graph data structure (e.g., adjacency list or matrix) with operations like adding edges and traversing (e.g., BFS, DFS).
-
Look for Comments:
- The code should have comments explaining what each function or block of code does.
-
Check the
mainFunction:- The
mainfunction usually demonstrates how the data structure or algorithm works.
- The
-
Experiment:
- Modify the code, add new features, or test edge cases to understand it better.
If you want to run the stack implementation (stack.c), follow these steps:
- Compile the code:
gcc stack.c -o stack
- Run the executable:
./stack
If the stack code is implemented correctly, it will demonstrate stack operations like push, pop, and peek.