plz tell me d error in this dfs program in c...
#include<stdio.h>
#include<conio.h>
int stack[20],top=-1;
int vis[20];
int a[20][20];
void dfs(int s,int n);
void push(int item);
int pop();
void dfs(int s,int n)
{
int i,k;
push(s);
vis[s]=1;
k=pop();
if(k!=0)
printf("\%d",k);
while(k!=0)
{
for(i=1;i<=n;i++)
if((a[k][i]!=0)&&(vis[i]=0))
{
push(i);
vis[i]=1;
}
k=pop();
if(k!=0)
printf("\n%d",k);
}
for(i=1;i<=n;i++)
if(vis[i]==0)
dfs(i,n);
}
void push(int item)
{
if(top==19)
{
printf("\nstack overflow");
}
top++;
stack[top]=item;
}
int pop()
{
if(top==-1)
{
printf("\nstack is empty");
}
else
{
printf("%d element is popped out of the stack",stack[top--]);
}
}
int main()
{
int i,j,s,n;
printf("\nenter the no of vertices");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("\nEnter 1 if %d has a node %d else 0",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\nADJACENCY MATRIX:");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("\n%d",a[i][j]);
}
}
for(i=1;i<=n;i++)
vis[i]=0;
printf("\nEnter the source vertex");
scanf("%d",&s);
dfs(s,n);
getch();
return(0);
}
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment