Professional Documents
Culture Documents
Άσκηση 5-1
#include <stdio.h>
#define SIZE 8
3
int main() {
int i, edges, selection, u, v, G[SIZE][SIZE], visited[SIZE];
do {
printf("\nChoose one of the following:\n");
printf("1. Display graph\n");
printf("2. DFS\n");
printf("3. BFS\n");
printf("0. Exit\n");
scanf("%d", &selection);
switch (selection) {
case 0:
break;
case 1:
printf("Adjacency Matrix\n");
displayGraph(G);
break;
case 2:
printf("Enter starting node for Depth First Search: ");
scanf("%d", &v);
for (i = 0; i < SIZE; i++)
visited[i] = 0;
dfs(G, visited, v);
break;
case 3:
printf("Enter starting node for Breadth First Search : ");
scanf("%d", &v);
for (i = 0; i < SIZE; i++)
visited[i] = 0;
bfs(G, visited, v);
break;
default:
printf("Wrong choice\n");
break;
}
} while (selection != 0);
return 0;
}