#include<iostream>
#define SIZE
using namespace std;
class Dfs
{
public:
Dfs();
void insert();
void traverse();
void initialize();
private:
int status*;
int cost**;
int stack*;
int top ;
int vertices;
int edges;
int k ;
};
Dfs :: Dfs()
{
top = 0 ;
k = 0 ;
edges = 0;
vertices = 0 ;
status = new int[SIZE];
stack = new int[SIZE];
cost = new int*[SIZE];
initialize();
}
void Dfs :: initialize()
{
for(int i = 0 ; i < SIZE ; i++)
{
cost[i] = new int[SIZE];
status[i] = 0 ;
}
}
void Dfs :: insert()
{
int i = 0 , j = 0 ;
cout << "Enter number of vertices (1 - 12)" <<endl;
cin>>vertices;
cout << "Enter number of edges" << endl;
cin>>edges;
cout << "Enter the edges" << endl;
for(k = 1 ; k <= edges ; k ++)
{
cin >> i >> j;
cost[i][j] = 1 ;
}
}
void Dfs :: traverse()
{
int v = 0 ;
cout << "Enter The initial vertex" << endl;
cin >> v;
k = 0;
stack[++top] = v;
while(top != 0 )
{
status[v] = 2;
cout << v <<" " ;
for(int i = 1 ; i <= 11 ; i++ )
{
if( (cost[v][i] == 1) && (status[i] == 0) )
{
stack[++top] = i ;
status[i] = 1 ;
}
}
v = stack[top--];
}
}
int main()
{
Dfs obj;
obj.insert();
obj.traverse();
cin.get();
cin.get();
return 0 ;
}
BY : SAURABH BHATIA
#define SIZE
using namespace std;
class Dfs
{
public:
Dfs();
void insert();
void traverse();
void initialize();
private:
int status*;
int cost**;
int stack*;
int top ;
int vertices;
int edges;
int k ;
};
Dfs :: Dfs()
{
top = 0 ;
k = 0 ;
edges = 0;
vertices = 0 ;
status = new int[SIZE];
stack = new int[SIZE];
cost = new int*[SIZE];
initialize();
}
void Dfs :: initialize()
{
for(int i = 0 ; i < SIZE ; i++)
{
cost[i] = new int[SIZE];
status[i] = 0 ;
}
}
void Dfs :: insert()
{
int i = 0 , j = 0 ;
cout << "Enter number of vertices (1 - 12)" <<endl;
cin>>vertices;
cout << "Enter number of edges" << endl;
cin>>edges;
cout << "Enter the edges" << endl;
for(k = 1 ; k <= edges ; k ++)
{
cin >> i >> j;
cost[i][j] = 1 ;
}
}
void Dfs :: traverse()
{
int v = 0 ;
cout << "Enter The initial vertex" << endl;
cin >> v;
k = 0;
stack[++top] = v;
while(top != 0 )
{
status[v] = 2;
cout << v <<" " ;
for(int i = 1 ; i <= 11 ; i++ )
{
if( (cost[v][i] == 1) && (status[i] == 0) )
{
stack[++top] = i ;
status[i] = 1 ;
}
}
v = stack[top--];
}
}
int main()
{
Dfs obj;
obj.insert();
obj.traverse();
cin.get();
cin.get();
return 0 ;
}
BY : SAURABH BHATIA
the program is displaying with errors ..please first correct them and then put it on the net....
ReplyDeleteAfter implementing i have uploaded this program. kindly post what type of errors you are getting.
ReplyDelete