Skip to content

Commit ece416e

Browse files
committed
Adjancey Matrix
1 parent ce99849 commit ece416e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Author : Robin Singh
3+
Implementation Of Adjancey matrix
4+
"""
5+
class Graph:
6+
def __init__(self,no_of_verices):
7+
self.Nodes = no_of_verices
8+
self.matrix = []
9+
self.make_matrix()
10+
11+
def make_matrix(self):
12+
for i in range(self.Nodes):
13+
v =[]
14+
for i in range(self.Nodes):
15+
v.append(0)
16+
self.matrix.append(v)
17+
18+
def _edge_add(self,node1,node2):
19+
self.matrix[node1-1][node2-1]=1
20+
self.matrix[node2-1][node1-1]=1
21+
22+
def print_matrix(self):
23+
for row in self.matrix:
24+
print(row)
25+
return print(row)
26+
27+
28+
29+
if __name__ == '__main__':
30+
31+
n = int(input("Entre No Of Nodes(Vertices)"))
32+
g =Graph(n)
33+
while(1):
34+
ch = int(input("1.Add Edge\t2.Print Adjancey Matrix\t3.Exit"))
35+
if ch == 3:
36+
break
37+
elif ch ==1:
38+
n1 = int(input("Entre Value Of NODE 1"))
39+
n2 = int(input("Entre Value Of NODE 2"))
40+
g._edge_add(n1,n2)
41+
42+
elif ch ==2:
43+
g.print_matrix()
44+
else:
45+
print("INVALID OPTION")
46+
47+

0 commit comments

Comments
 (0)