From dc5e86b7013cb02ceb0a11f32afb4a2b8f7d3ae1 Mon Sep 17 00:00:00 2001 From: Alvin Nguyen Date: Mon, 9 Oct 2017 17:00:37 -0700 Subject: [PATCH 1/2] Fixed compilation errors, fixes for readability/convention, changed double equals to boolean equality operator 'is' --- data_structures/Graph/Breadth_First_Search.py | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/data_structures/Graph/Breadth_First_Search.py b/data_structures/Graph/Breadth_First_Search.py index 1a3fdfd4d..9cb234856 100644 --- a/data_structures/Graph/Breadth_First_Search.py +++ b/data_structures/Graph/Breadth_First_Search.py @@ -1,9 +1,9 @@ class GRAPH: """docstring for GRAPH""" def __init__(self, nodes): - self.nodes=nodes - self.graph=[[0]*nodes for i in range (nodes)] - self.visited=[0]*nodes + self.nodes = nodes + self.graph = [[0]*nodes for i in range (nodes)] + self.visited = [0]*nodes def show(self): @@ -23,7 +23,7 @@ class GRAPH: v = queue[0] for u in range(self.vertex): if self.graph[v][u] == 1: - if visited[u]== False: + if visited[u] is False: visited[u] = True queue.append(u) print('%d visited' % (u +1)) @@ -41,30 +41,32 @@ g.add_edge(4,8) g.add_edge(5,9) g.add_edge(6,10) g.bfs(4) -======= - print self.graph + +print(self.graph) def add_edge(self, i, j): self.graph[i][j]=1 self.graph[j][i]=1 - def bfs(self,s): - queue=[s] - self.visited[s]=1 - while len(queue)!=0: - x=queue.pop(0) + def bfs(self, s): + queue = [s] + self.visited[s] = 1 + while len(queue)!= 0: + x = queue.pop(0) print(x) - for i in range(0,self.nodes): - if self.graph[x][i]==1 and self.visited[i]==0: + for i in range(0, self.nodes): + if self.graph[x][i] == 1 and self.visited[i] == 0: queue.append(i) - self.visited[i]=1 + self.visited[i] = 1 -n=int(input("Enter the number of Nodes : ")) -g=GRAPH(n) -e=int(input("Enter the no of edges : ")) +n = int(input("Enter the number of Nodes : ")) +g = GRAPH(n) +e = int(input("Enter the no of edges : ")) print("Enter the edges (u v)") -for i in range(0,e): - u,v=map(int, raw_input().split()) - g.add_edge(u,v) -s=int(input("Enter the source node :")) + +for i in range(0, e): + u ,v = map(int, raw_input().split()) + g.add_edge(u, v) + +s = int(input("Enter the source node :")) g.bfs(s) From ab058ab0b51486f892a1b59a22631eff5083c241 Mon Sep 17 00:00:00 2001 From: Alvin Nguyen Date: Mon, 9 Oct 2017 17:05:14 -0700 Subject: [PATCH 2/2] changed rigt->right, a typo fix. --- data_structures/Binary Tree/binary_seach_tree.py | 6 +++--- data_structures/Graph/Breadth_First_Search.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data_structures/Binary Tree/binary_seach_tree.py b/data_structures/Binary Tree/binary_seach_tree.py index 1dac948ae..0b1726534 100644 --- a/data_structures/Binary Tree/binary_seach_tree.py +++ b/data_structures/Binary Tree/binary_seach_tree.py @@ -8,7 +8,7 @@ class Node: def __init__(self, label): self.label = label self.left = None - self.rigt = None + self.right = None def getLabel(self): return self.label @@ -23,10 +23,10 @@ class Node: self.left = left def getRight(self): - return self.rigt + return self.right def setRight(self, right): - self.rigt = right + self.right = right class BinarySearchTree: diff --git a/data_structures/Graph/Breadth_First_Search.py b/data_structures/Graph/Breadth_First_Search.py index 9cb234856..92a6e819b 100644 --- a/data_structures/Graph/Breadth_First_Search.py +++ b/data_structures/Graph/Breadth_First_Search.py @@ -67,6 +67,6 @@ print("Enter the edges (u v)") for i in range(0, e): u ,v = map(int, raw_input().split()) g.add_edge(u, v) - + s = int(input("Enter the source node :")) g.bfs(s)