-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathGraph.cpp
47 lines (42 loc) · 903 Bytes
/
Graph.cpp
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
#include<iostream>
using namespace std;
struct Edge
{
int start{0},end{0};
};
main()
{
int ver{0},edges{0},**ptr;
cout<<"\nEnter number of vertices ";
cin>>ver;
cout<<"\nEnter number of edges ";
cin>>edges;
Edge * arr = new Edge[edges];
ptr = new int * [ver];
for(int i=0;i<ver;i++)
ptr[i]= new int [ver]{0};
cout<<"\nEnter the value ";
for(int i=0;i<edges;i++)
{
int st,en;
cin>>st>>en;
if(st>=ver||en>=ver)
{
cout<<"\nInvalid input ";
i--;
}
else
{
arr[i].start=st;
arr[i].end=en;
ptr[st][en] = ptr[en][st] = 1;
}
}
cout<<endl<<endl;
for(int i=0;i<ver;i++)
{
for(int j=0;j<ver;j++)
cout<<ptr[i][j]<<"\t";
cout<<endl;
}
}