-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph Using Array.cpp
60 lines (59 loc) · 945 Bytes
/
Graph Using Array.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
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<iostream>
using namespace std;
struct vertices{
char info[20];
};
void joingraph(int ar[][3],int node1,int node2,int wt)
{
ar[node1][node2]=wt;
}
void removegraph(int ar[][3],int node1,int node2)
{
ar[node1][node2]=1;
}
int main()
{
vertices *data;
int **adj;
int vertix;
cout<<"Please Enter The Number of Vertices";
cin>>vertix;
data=new vertices[vertix];
cout<<"Vertix Created";
adj=new int*[vertix];
for(int i=0;i<vertix;i++)
{
adj[i]=new int[vertix];
}
cout<<"**Adjacency Matrix Created**"<<endl;
cout<<"Enter Data For the Vertices";
for(int i=0;i<vertix;i++)
{
cin>>data[i].info;
}
for(int i=0;i<vertix;i++)
{
for(int j=0;j<vertix;j++)
{
adj[i][j]=1;
}
}
adj[1][2]=3;
adj[2][0]=5;
adj[2][1]=7;
adj[1][0]=4;
cout<<endl;
for(int i=0;i<vertix;i++)
{
for(int j=0;j<vertix;j++)
{
if(adj[i][j]!=1)
{
cout<<adj[i][j]<<" ";
}
else
cout<<"1"<< " ";
}
cout<<endl;
}
}