This is a sub page help code for Graph Simulator
/*help.h*/
include
using namespace std;
struct node
{
int name;
int cost;
struct node *connect;
struct node *next;
//struct node *back;
};
class graph
{
public:
node* p;
graph()
{
p = NULL;
}
int displaymenu();
void adb(struct node *q,int x);
void display(struct node *q);
void ade(struct node *q,int x,int c);
void search(struct node *q,int x, int y,int c);
void disconn(struct node *q,int x,int y);
void delnode(struct node *q,int d);
};
int graph::displaymenu()
{
int c;
cout<<"\n---Network Configuration---";
cout<<"\n1.Add a Node in the Network";
cout<<"\n2.Connect the Node";
cout<<"\n3.Delete the Node";
cout<<"\n4.Delete the Connection";
cout<<"\n5.Display the Network Map";
cout<<"\n6.Exit";
cout<<"\n\tchoice=";
cin>>c;
return c;
}
void graph::adb(struct node *q,int x)
{
struct node *temp;
temp=new node;
temp->name=x;
temp->next=q;
temp->connect=NULL;
q=temp;
p=q;
}
void graph::display(struct node *q)
{
struct node *temp1;
struct node *temp2;
temp1=q;
temp2=q;
cout<<"\nNodes";
while(temp1 != NULL)
{
cout << "\n" << temp1->name;
temp2 = temp2->connect;
while(temp2 != NULL)
{
cout << "\t->" <
}
temp1 = temp1->next;
temp2 = temp1;
}
}
void graph::ade(struct node *q,int x, int c)
{
struct node *temp,*r;
if(q==NULL)
{
temp=new node;
temp->name=x;
temp->cost=c;
temp->connect=NULL;
q=temp;
p=q;
}
else
{
temp=q;
while(temp->connect!=NULL)
{
temp=temp->connect;
}
r=new node;
r->name=x;
r->cost=c;
r->connect=NULL;
temp->connect=r;
}
}
void graph::search(struct node *q,int x, int y, int c)
{
struct node *temp;
int loc=1;
temp=q;
while(temp->name!=x)
{
temp=temp->next;
if(temp==NULL)
{
cout<<"number not found";
return;
}
loc=loc+1;
}
graph::ade(temp,y,c);
return;
}
void graph::disconn(struct node *q,int x,int y)
{
struct node *temp,*r,*k;
temp=q;
r=NULL;
k=NULL;
while(temp->name!=x)
{
temp=temp->next;
}
while(temp->connect->name!=y)//||temp==NULL)
{
temp=temp->connect;
}
/*if(temp==NULL)
{
cout<<"Connection Not Found!!";
return;
}*/
r=temp->connect;
k=temp->connect->connect;
temp->connect = k;
delete r;
}
void graph::delnode(struct node *q, int d)
{
struct node *temp,*r,*k,*j,*m,*n,*o;
temp=q;
r=NULL;
k=NULL;
n=NULL;
if(temp->name==d)
{
q=temp->next;
p=q;
delete temp;
}
else
{
while(temp->next->name!=d)
{
temp=temp->next;
}
r=temp->next;
k=temp->next->next;
temp->next=k;
delete r;
}
j=q;
m=q;
while(j!=NULL)
{
while(m->connect!=NULL&&m->connect->name!=d)
{
m=m->connect;
}
if(m->connect==NULL)
{
goto loop;
}
else
{
n=m->connect;
o=m->connect->connect;
m->connect=o;
delete n;
}
loop: j=j->next;
m=j;
}
}