عنوان پروژه

 برنامه

سورس جستجوی اول عمق DFS سی پلاس

سورس DFS سی پلاس

توضیحات :

نوع فایل

فرمت

سورس زبان سی پلاس پلاس

CPP , EXE

پیش نمایش از سورس کد پروژه

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
# define MAX 20
# define TRUE 1
# define FALSE 0
int g[MAX][MAX];
int v[MAX];
int n;
void main()
{
int v1,v2;
char ans;
void create();
void dfs(int);
clrscr();
create();
cout<<“Adjacency Matrix:\n”;
for(v1=1;v1<=n;v1++)
{
for(v2=1;v2<=n;v2++)
{
cout<<g[v1][v2]<<“\t”;
}
cout<<“\n”;
}
getch();
do
{
for(v1=1;v1<=n;v1++)
v[v1]=FALSE;
cout<<“\nEnter the vertex from which to traverse\n”;
cin>>v1;
if(v1>=MAX)
cout<<“\nInvalid vertex”;
else
{
cout<<“\nThe depth first search is:\n”;
dfs(v1);
}
cout<<“\nDo you want to traverse by any other node\n”;
ans=getch();
}
while(ans==’y’);
}
void dfs(int v1)
{
int v2;
cout<<v1<<“\t”;
v[v1]=TRUE;
for(v2=1;v2<=MAX;v2++)
if(g[v1][v2]==TRUE && v[v2]==FALSE)
dfs(v2);
}
void create()
{
int ch,v1,v2,flag;
char ans=’y’;
for(v1=1;v1<=n;v1++)
for(v2=1;v2<=n;v2++)
g[v1][v2]=FALSE;
cout<<“\nEnter the number of nodes\n”;
cin>>n;
cout<<“\nEnter the vertices starting from 1:\n”;
do
{
cout<<“\nEnter the vertices v1 & v2:\n”;
cin>>v1>>v2;
if(v1>n||v2>n)

}

dfs

======