Help with 1 function

I need a function which count and display nodes with maximum outgoing edges/arcs/ in graph

Here is the code, i have to add this function to it. Anyone?

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include<iostream>
using namespace std;

const int n=10;
 struct link
 {
	 char key;
	 link *next;
 }
 *g[n];

 void print(link *g[n])
 {
	 link *p;
	 {
		 for(int i=0; i<n; i++)
		 {
			 if(g[i])
			 {
				 p=g[i];
				 while(p)
				 {
					 cout<<p->key;
					 p=p->next;
				 }
				 cout<<endl;
			 }
		 }
	 }
 }

 void init(link *g[n])
 {
	 for(int i=0;i<n;i++)
		 g[i]=NULL;
 }

int search_node(char c, link *g[n])
 {
	 int flag=0;
	 for(int i=0;i<n;i++)
		 if(g[i])
			 if(g[i]->key==c)
				 flag=1;
	 return flag;
 }

int search_arc(char c1, char c2, link *g[n])
 {
	 int flag=0;
	 if(search_node(c1,g) && (search_node(c2,g)))
	 {
		 int i=0;
		 while(g[i]==NULL||g[i]->key!=c1)i++;
		 link *p=g[i]->next;
		 if(p)
		 {
			 while(p->key!=c2 && p->next)
				 p=p->next;
			 if(p->key==c2)
				 flag=1;
		 }
	 }
	 return flag;
}

 void add_node(char c, link *g[n])
 {
	 if(search_node(c,g))
		 cout<<"In Exsitsing node: ";
	 else
		 {int i=0;
	 while(g[i]&&i<n) i++;
	 if(g[i]==NULL)
	 {
		 g[i]=new link;
		 g[i]->key=c;
		 g[i]->next=NULL;
	 }
	 else cout<<"Overflow";
 }
 }

 void add_arc (char c1, char c2, link *g[n])
 {
	 if (search_arc(c1,c2,g))
	 {
		 cout<<"In Existing arc";}
	 else
	 {
		 if(!(search_node(c1,g)))
			 add_node(c1,g);
		 if(!(search_node(c2,g)))
			 add_node(c2,g);
		 int i=0;
		 while(g[i]==NULL||g[i]->key!=c1)
			 i++;
		 link *p=new link;
		 p->key=c2;
		 p->next=g[i]->next;
		 g[i]->next=p;
	 }
	 }


 int main()
 {
	char c,k;

	int m;
	do
	{
		cout<<"\n  MENU   ";
		cout<<"\n 1.Add node ";
		cout<<"\n 2.Add arc ";
		cout<<"\n 3.Print All ";
		cout<<"\n 4.End ";
		cout<<"\n Choice: ";
		cin>>m;

		switch(m)
		{
		case 1:
			{
				cout<<"\n Node: ";
				cin>>c;
				add_node(c, g);
				break;
			}
		case 2:
			{
				cout<<"\n First node";
				cin>>c;
				cout<<"\n Second node";
				cin>>k;
				add_arc(c, k, g);
				break;
			}
		case 3:
			{
				print(g);
			}
		}
	}
	while(m!=4);
 return 0;
 }


Topic archived. No new replies allowed.