89 166
Assignments Done
98.2%
Successfully Done
In August 2020

# Answer to Question #27439 in C for Jovi

Question #27439
In C language. Write a Code for Implementation of Depth-First Traversal and Breath-First Traversal on a given graph havin (8 vertices and 12 sides)
1
2013-04-03T10:55:23-0400
#include <stdio.h>

void dfs_exec(int adj[8][8], int visited[8], int v) {
printf("%d ", v);
visited[v] = 1;
int i;
for (i = 0; i < 8; i++)
& if (adj[v][i] == 1 && visited[i] == 0)
}

printf("Depth-First Traversal:\n");
int visited[8] = {};
int i;
for (i = 0; i < 8; i++)
& if (visited[i] == 0) {
printf("\n");
& }
}

printf("Breath-First Traversal:\n");
int Q[8];
int visited[8] = {};
int k;
for (k = 0; k < 8; k++)
& if (visited[k] == 0) {
& int head = 0, tail = 0;
& Q[0] = k;
& visited[0] = 1;
& while (head <= tail) {
printf("%d ", v);
int i;
for (i = 0; i < 8; i++)
if (adj[v][i] == 1 && visited[i] == 0) {
& Q[++tail] = i;
& visited[i] = 1;
}
& }
& printf("\n");
& }
}

int main() {
int i;
for (i = 0; i < 12; i++) {
& printf("Input edge %d vertices: ", i);
& int a, b;
& scanf("%d %d", &a, &b);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!