-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.cpp
More file actions
59 lines (59 loc) · 1.4 KB
/
Copy path4.cpp
File metadata and controls
59 lines (59 loc) · 1.4 KB
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
#include<iostream>
#include<vector>
using namespace std;
main()
{
int V, E, i, j, u, v, c;
cout<<"Enter the number of vertices\n";
cin>>V;
cout<<"Enter the number of edges\n";
cin>>E;
cout<<"Enter 1 for directed graph and 2 for undirected graph\n";
cin>>c;
int adj[V+1][V+1];
for(i=0;i<V+1;i++)
{
for(j=0;j<V+1;j++)
adj[i][j]=0;
}
for(int i=0;i<E;i++)
{
cout<<"Edge "<<i+1;
cout<<"\nEnter source vertex\n";
cin>>u;
while(u<=0 || u>V)
{
cout<<"Enter valid source vertex\n";
cout<<"Enter source vertex ";
cin>>u;
}
cout<<"Enter destination vertex\n";
cin>>v;
while(v<=0 || v>V)
{
cout<<"Enter valid source vertex\n";
cout<<"Enter source vertex ";
cin>>v;
}
adj[u][v]=1;
if(c==2)
adj[v][u]=1;
}
int idegree,odegree;
for(i=1;i<V+1;i++)
{
//cout<<"Node "<<i;
idegree=odegree=0;
for(j=1;j<V+1;j++)
{
if(adj[i][j]==1)
odegree++;
if(adj[j][i]==1)
idegree++;
//if
}
cout<<"Node "<<i;
cout<<"\nIndegree is "<<idegree;
cout<<"\nOutdegree is "<<odegree<<endl;
}
}