-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLAB Q-13(2).cpp
More file actions
45 lines (43 loc) · 767 Bytes
/
Copy pathLAB Q-13(2).cpp
File metadata and controls
45 lines (43 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int a[10][10],i,j,k,n,stk[10],top,v,visit[10],visited[10],x,y;
main()
{
cout <<"enter no. of vertices SIR/MAM!";
cin >> n;
cout<<"sir please enter for undirected grah"<<endl;
cin>>x>>y;
if(x>=n&&y>=n)
cout<<"sir ji please enter within range"<<endl;
else
{
while(x!=-1&&y!=-1)
{
a[x][y]=1;
a[y][x]=1;
cin>>x>>y;
}
}
cout <<"enter initial vertex";
cin >>v;
cout <<"AFTER DFS ,SIR ORDER COMES -:"<<endl;
cout << v <<" ";
visited[v]=1;
k=1;
while(k<n)
{
for(j=n;j>=1;j--)
if(a[v][j]!=0 && visited[j]!=1 && visit[j]!=1)
{
visit[j]=1;
stk[top]=j;
top++;
}
v=stk[--top];
cout<<v << " ";
k++;
visit[v]=0; visited[v]=1;
}
}