Untitled
unknown
plain_text
a year ago
591 B
4
Indexable
LAB 4A: Write program to implement the DFS algorithm for a graph.
#include<stdio.h>
int top-1,a[20][20], vis[20], stack[20];
void dfs(int s,int n);
void push(int item);
int pop();
void main()
{
int n,e,i,s,j,u,v;
printf("Enter the number of vertices in the graph: "); scanf("%d", &n);
printf("Enter the number of edges in the graph: "); scanf("%d", &e);
printf("Enter the edges (u, v):\n"); for (i = 1; i<=e; i++)
{
scanf("%d %d", &u, &v); a[u][v] = 1;
}
printf("THE ADJACENCY MATRIX IS\n"); for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++) { printf("%d",a[i][j]);
}
printf("\n");
}Editor is loading...
Leave a Comment