#include<string>
#include<iostream>
using namespace std;
const int Max=5;
#include<iostream>
using namespace std;
const int Max=5;
class graph
{
private:
int vertices[Max];
int edges[Max][Max];
public:
graph()
{
for(int i=0;i<Max;i++)
{
vertices[i]=0;
}
for(int i=0;i<Max;i++)
{
for(int j=0;j<Max;j++)
{
edges[i][j]=0;
}
}
}
void insertvertex(int v)
{
int i =0;
vertices[i]=v;
i++;
}
void insertedge(int v,int u)
{
edges[v][u]=1;
}
void adjacent(int v)
{
for(int j=0;j<Max;j++)
{
cout<<edges[v][j]<<"\t"<<" ";
}
cout<<endl;
}
};
{
private:
int vertices[Max];
int edges[Max][Max];
public:
graph()
{
for(int i=0;i<Max;i++)
{
vertices[i]=0;
}
for(int i=0;i<Max;i++)
{
for(int j=0;j<Max;j++)
{
edges[i][j]=0;
}
}
}
void insertvertex(int v)
{
int i =0;
vertices[i]=v;
i++;
}
void insertedge(int v,int u)
{
edges[v][u]=1;
}
void adjacent(int v)
{
for(int j=0;j<Max;j++)
{
cout<<edges[v][j]<<"\t"<<" ";
}
cout<<endl;
}
};
main()
{
graph obj;
char c;
char h;
int edge1;
int edge2;
int v;
int vertx=0;
string city[5];
do
{
int i=0;
cout<<"please enter city name"<<endl;
cin>>city[vertx];
obj.insertvertex(vertx);
cout<<"do you want to insert again ";
cin>>c;
vertx ++;
}
{
graph obj;
char c;
char h;
int edge1;
int edge2;
int v;
int vertx=0;
string city[5];
do
{
int i=0;
cout<<"please enter city name"<<endl;
cin>>city[vertx];
obj.insertvertex(vertx);
cout<<"do you want to insert again ";
cin>>c;
vertx ++;
}
while(c=='Y'||c=='y'&&vertx<5);
system("CLS");
do
{
system("CLS");
do
{
int j=0;
cout<<"please Enter the 1st city"<<endl;
for(int z=0;z<5;z++)
{
cout<<z<<":"<<city[z]<<endl;
cout<<"please Enter the 1st city"<<endl;
for(int z=0;z<5;z++)
{
cout<<z<<":"<<city[z]<<endl;
}
cin>>edge1;
cout<<"Please the select the 2nd city"<<endl;
for(int z=0;z<5;z++)
{
cout<<z<<":"<<city[z]<<endl;
cin>>edge1;
cout<<"Please the select the 2nd city"<<endl;
for(int z=0;z<5;z++)
{
cout<<z<<":"<<city[z]<<endl;
}
//cout<<"please insert vertex2"<<endl;
cin>>edge2;
obj.insertedge(edge1,edge2);
//cout<<"please insert vertex2"<<endl;
cin>>edge2;
obj.insertedge(edge1,edge2);
cout<<"do you want to insert again "<<endl;
cin>>h;
j++;
system("CLS");
}
cin>>h;
j++;
system("CLS");
}
while(h=='Y'||h=='y');
system("CLS");
char l;
do
system("CLS");
char l;
do
{
cout<<"enter the vertex whoes adjacent you want to find"<<endl;
cin>>v;
cout<<endl;
cout<<"For "<<city[v]<<endl<<endl;
for(int i=0;i<5;i++)
{
cout<<city[i]<<"\t";
}
cout<<endl;
obj.adjacent(v);
cout<<"do you want to insert again "<<endl;
cin>>l;
system("CLS");
}
while(l=='Y'|| l=='y');
system("pause");
}
cout<<"enter the vertex whoes adjacent you want to find"<<endl;
cin>>v;
cout<<endl;
cout<<"For "<<city[v]<<endl<<endl;
for(int i=0;i<5;i++)
{
cout<<city[i]<<"\t";
}
cout<<endl;
obj.adjacent(v);
cout<<"do you want to insert again "<<endl;
cin>>l;
system("CLS");
}
while(l=='Y'|| l=='y');
system("pause");
}
Post A Comment:
0 comments: