I need to make a program that searches for node with two arches to it. ->()<-
Please help. I have this but I dont know how to ivert it to mine. The following code is for the opposite <-()->.
#include <iostream>
using namespace std;
const int n=8;
struct link
{
char key;
link *next;
}*g[n];
void init(link *G[n]);
int search_node(link *G[n], char c);
int search_arc(link *G[n], char c1, char c2);
void add_node(link *G[n], char c);
void add_arc(link *G[n], char c1, char c2);
void list_node(link *G[n]){
cout<<"\n";
for(int i=0; i<n; i++){
if(g[i]){
cout<<g[i]->key;
}
}
}
void main()
{
add_node(g, 'A');
add_node(g, 'B');
add_node(g, 'C');
add_node(g, 'D');
add_node(g, 'E');
add_node(g, 'F');
add_node(g, 'G');
add_node(g, 'H');
add_arc(g, 'A', 'B');
add_arc(g, 'A', 'C');
add_arc(g, 'H', 'C');
add_arc(g, 'H', 'D');
add_arc(g, 'B', 'F');
add_arc(g, 'B', 'H');
add_arc(g, 'C', 'D');
add_arc(g, 'D', 'F');
add_arc(g, 'E', 'G');
add_arc(g, 'G', 'E');
for(int i=0; i<n; i++)
{
if(g[i]->next!=NULL && g[i]->next->next!=NULL)
cout<<"\nTwo pair of arc from one node: "<<g[i]->key;
}
int tra;
cin>>tra;
}
void init(link *G[n])
{
for (int i=0; i<n; i++)
G[i]=NULL;
}
int search_node(link *G[n], char c)
{
int flag=0;
for(int i=0; i<n; i++)
{
if(G[i])
if(G[i]->key==c)
{
flag=1;
break;
}
}
return flag;
}
int search_arc(link *G[n], char c1, char c2)
{
int flag=0;
if(search_node(G,c1)&&search_node(G,c2))
{
int i=0;
while(G[i]->key!=c1)i++;
link *p=G[i];
while(p->key!=c2&&p->next!=NULL)p=p->next;
if(p->key==c2)flag=1;
}
return flag;
}
void add_node(link *G[n], char c)
{
if(search_node(G,c))
cout<<"\nNode exists";
else
{
int j=0;
while(G[j]&&(j<n))j++;
if(G[j]==NULL)
{
G[j]=new link;
G[j]->key=c;
G[j]->next=NULL;
}
else cout<<"\noverflow occured";
}
}
void add_arc(link *G[n], char c1, char c2)
{
int i=0;
link *p;
if(search_arc(G,c1,c2))
cout<<"\nArc exists";
else
{
if(!search_node(G,c1)) {cout<<"DOBB";add_node(G,c1);}
if(!search_node(G,c2)) {cout<<"DOBB";add_node(G,c2);}
while(G[i]->key!=c1) i++;
p=new link;
p->key=c2;
p->next=G[i]->next;
G[i]->next=p;
}
}
What I have tried:
Well, the line which should be fixes is with comment but I do not know how to change it. Another thing is, there are functions for creating arches and adding nodes. But the program does not ask me to do it, they are made in the code. Is there a mistake?