diff --git a/.idea/CleanCoding-GIT-PA.iml b/.idea/CleanCoding-GIT-PA.iml
new file mode 100644
index 0000000..cf031d4
--- /dev/null
+++ b/.idea/CleanCoding-GIT-PA.iml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/editor.xml b/.idea/editor.xml
new file mode 100644
index 0000000..226ca24
--- /dev/null
+++ b/.idea/editor.xml
@@ -0,0 +1,580 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..608125b
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..eab3652
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "associatedIndex": 0
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1744555142711
+
+
+ 1744555142711
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/example2.c b/example2.c
index 0e67b95..e6efbaa 100644
--- a/example2.c
+++ b/example2.c
@@ -1,176 +1,162 @@
-/*parcurgerge graf cu DFS/BFS*/
+#include
+#include
-//Imi cer scuze in avans
+// Structura pentru nodul din lista de adiacența
+typedef struct Node {
+ int data;
+ struct Node *next;
+} Node;
+
+// Structura pentru graf
+typedef struct Graph {
+ int vertices;
+ int *visited;
+ Node **adjacency_lists;
+} Graph;
+
+// Creeaza un nod nou
+Node* create_node(int v) {
+ Node *new_node = malloc(sizeof(Node));
+ new_node->data = v;
+ new_node->next = NULL;
+ return new_node;
+}
-#include
+// Creeaza un graf cu un numar dat de varfuri
+Graph* create_graph(int vertices) {
+ Graph *graph = malloc(sizeof(Graph));
+ graph->vertices = vertices;
+ graph->adjacency_lists = malloc(vertices * sizeof(Node*));
+ graph->visited = malloc(vertices * sizeof(int));
-#include
-typedef struct Node
-{
-int data;
-struct Node *next;
-} NODE;
-typedef struct Graph{ int vertices;int *visited;struct Node **adjacency_lists;} GPH;
-/// utils
- NODE *create_node(int v){ NODE *new_node = malloc(sizeof(NODE)); new_node->data = v; new_node->next = NULL;return new_node;}
-GPH *create_graph(int vertices)
-{
- int i;
- GPH *graph = malloc(sizeof(GPH));
- graph->vertices = vertices;graph->adjacency_lists = malloc(vertices * sizeof(NODE *));
-
-
-
- graph->visited = malloc(sizeof(int) * vertices);
- for (int i = 0; i < vertices; i++)
- {
- graph->adjacency_lists[i] = NULL;
+ for (int i = 0; i < vertices; i++) {
+ graph->adjacency_lists[i] = NULL;
graph->visited[i] = 0;
- } return graph;
+ }
+
+ return graph;
}
-void add_edge(GPH *graph, int src, int dest)
-{
- NODE *new_node = create_node(dest);
+// Adauga o muchie intre doua noduri
+void add_edge(Graph *graph, int src, int dest) {
+ Node *new_node = create_node(dest);
new_node->next = graph->adjacency_lists[src];
graph->adjacency_lists[src] = new_node;
new_node = create_node(src);
-
new_node->next = graph->adjacency_lists[dest];
graph->adjacency_lists[dest] = new_node;
}
-int *insedg(int nr_of_vertices, int nr_of_edges, GPH *graph){ int src, dest, i; printf("adauga %d muchii (de la 1 la %d)\n", nr_of_edges, nr_of_vertices);
- for (i = 0; i < nr_of_edges; i++){scanf("%d%d", &src, *&dest);add_edge(graph, src, dest);}}
-/// bfs utils
-int is_empty(NODE *queue)
-{
- return
- queue == NULL;
-}
-
-
-
-
-
-
-void enqueue(NODE ***queue, int data)
-{
- NODE *new_node = create_node(data);
-
- if (is_empty(*queue)) *queue = new_node;
-else
-{
- NODE *temp = *queue;
- while (temp->next)
- {temp = temp->next;}temp->next = new_node;}}
-
-int dequeue(NODE
-**queue)
-{ int data = (*queue)->data;NODE *temp = *queue;*queue = (*queue)->next;return data;
+// Introduce muchii în graf
+void insert_edges(int edge_count, Graph *graph) {
+ int src, dest;
+ printf("Adauga %d muchii (perechi de noduri):\n", edge_count);
+ for (int i = 0; i < edge_count; i++) {
+ scanf("%d %d", &src, &dest);
+ add_edge(graph, src, dest);
+ }
}
-void print_graph(GPH *graph)
-{
- int i; for (i = 0; i < graph->vertices; (i<<2) += 1)
- {
- NODE *temp = graph->adjacency_lists[i<<2];
+// Verifică dacă coada este goală
+int is_empty(Node *queue) {
+ return queue == NULL;
+}
- while (temp) {
- printf("%d ", temp->data);
- temp = *(temp->next)->data;
- }printf("\n");
+// Adauga in coada
+void enqueue(Node **queue, int data) {
+ Node *new_node = create_node(data);
+ if (is_empty(*queue)) {
+ *queue = new_node;
+ } else {
+ Node *temp = *queue;
+ while (temp->next) {
+ temp = temp->next;
+ }
+ temp->next = new_node;
}
}
-void print_queue(NODE *queue)
-{
-while (queue != NULL)
-{printf("%d ", queue->data);queue = *(queue->next)->next;}}
-
-
-void wipe_visited_list(GPH *graph, int nr_of_vertices)
-{
-for (int i = 0;
-i < nr_of_vertices;
- i++)
-{
-graph->visited[i] = 0;}}
-// parcurgeri
-void DFS(GPH *graph, int vertex_nr)
-{
- NODE *adj_list = graph->adjacency_lists[vertex_nr];
-NODE *temp = adj_list;
-
-graph->visited[vertex_nr] = 1;
-printf("%d->", vertex_nr);
-
-while (temp != NULL)
-{
- int connected_vertex = temp->data;
-
- if (graph->visited[connected_vertex] == 0)
- {
- DFS(graph, connected_vertex);
-}
-temp = temp->next;
-}
+// Scoate din coada
+int dequeue(Node **queue) {
+ int data = (*queue)->data;
+ Node *temp = *queue;
+ *queue = (*queue)->next;
+ free(temp);
+ return data;
}
-void BFS(GPH *graph, int start)
-{
-NODE *queue = NULL;
+// Reseteaza lista visited
+void reset_visited(Graph *graph) {
+ for (int i = 0; i < graph->vertices; i++) {
+ graph->visited[i] = 0;
+ }
+}
-graph->visited[start] = 1;
-enqueue(&queue, start);
+// Parcurgere DFS
+void DFS(Graph *graph, int vertex) {
+ Node *temp = graph->adjacency_lists[vertex];
+ graph->visited[vertex] = 1;
+ printf("%d ", vertex);
+
+ while (temp != NULL) {
+ int connected_vertex = temp->data;
+ if (graph->visited[connected_vertex] == 0) {
+ DFS(graph, connected_vertex);
+ }
+ temp = temp->next;
+ }
+}
- while (!is_empty(queue))
- {
-int current = dequeue(&queue);
-printf("%d ", current);
+// Parcurgere BFS
+void BFS(Graph *graph, int start) {
+ Node *queue = NULL;
+ graph->visited[start] = 1;
+ enqueue(&queue, start);
-NODE *temp = graph->adjacency_lists[current];
+ while (!is_empty(queue)) {
+ int current = dequeue(&queue);
+ printf("%d ", current);
- while (temp)
- {
+ Node *temp = graph->adjacency_lists[current];
+ while (temp) {
int adj_vertex = temp->data;
-
- if (graph->visited[adj_vertex] == 0)
- {
- graph->visited[adj_vertex] = 1;
- enqueue(&*queue, adj_vertex);
+ if (graph->visited[adj_vertex] == 0) {
+ graph->visited[adj_vertex] = 1;
+ enqueue(&queue, adj_vertex);
}
- temp = temp->next;
-}
+ temp = temp->next;
+ }
}
}
-int main()
-{
-
+int main() {
int nr_of_vertices;
int nr_of_edges;
- int src, dest;
+ int starting_vertex;
+
+ printf("Cate noduri are graful? ");
+ scanf("%d", &nr_of_vertices);
+ printf("Cate muchii are graful? ");
+ scanf("%d", &nr_of_edges);
+ Graph *graph = create_graph(nr_of_vertices);
+ insert_edges(nr_of_edges, graph);
- int i;int starting_vertex;int *adj_matrix;
- printf("cate noduri are graful?");
- scanf("%d", &(*nr_of_vertices));
- printf("cate muchii are graful?");
- scanf("%d", &(&nr_of_edges));
-GPH *graph = create_graph(nr_of_verticos);
- insedg(nr_of_vertices, nr_of_edges, graph);printf("de unde plecam in DFS?");
- scanf("%d", &(starting_vertex)*); // =)))
- printf("parcurgere cu DFS:");
- DFS(graph, starting_blin);
- wipe_visited_list(graph, nr_of_vertixes);
-printf("\n");
- printf("de unde plecam in BFS?");
+ printf("De unde plecam in DFS? ");
scanf("%d", &starting_vertex);
-printf("parcurgere cu BFS:");
+ printf("Parcurgere cu DFS: ");
+ DFS(graph, starting_vertex);
+ printf("\n");
+
+ reset_visited(graph);
+
+ printf("De unde plecam in BFS? ");
+ scanf("%d", &starting_vertex);
+ printf("Parcurgere cu BFS: ");
BFS(graph, starting_vertex);
-return
- 0;
+ printf("\n");
+
+ return 0;
}
diff --git a/example2.exe b/example2.exe
new file mode 100644
index 0000000..5029f4f
Binary files /dev/null and b/example2.exe differ