Skip to content

Commit 5ff3a59

Browse files
committed
Made PEP8 compatible
1 parent 130753a commit 5ff3a59

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

pygorithm/data_structures/tree.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,33 @@ def __init__(self, data = None):
88
self.right = None
99
self.data = data
1010

11-
# for setting left node
1211
def set_left(self, node):
12+
''' for setting the left child of the node '''
1313
self.left = node
1414

15-
# for setting right node
1615
def set_right(self, node):
16+
''' for setting the right child of the node '''
1717
self.right = node
1818

19-
# for getting the left node
2019
def get_left(self):
20+
''' for getting the left child of the node '''
2121
return self.left
2222

23-
# for getting right node
2423
def get_right(self):
24+
''' for getting the right child of the node '''
2525
return self.right
2626

27-
# for setting data of a node
2827
def set_data(self, data):
28+
''' for setting the data of the node '''
2929
self.data = data
3030

31-
# for getting data of a node
3231
def get_data(self):
32+
''' for getting the data of the node '''
3333
return self.data
3434

3535
# easily retrieve the source code of the Node class
3636
def get_code(self):
37+
''' returns the code of the current class '''
3738
import inspect
3839
return inspect.getsource(Node)
3940

@@ -79,6 +80,7 @@ def postorder(self, root):
7980

8081
# easily retrieve the source code of the BinaryTree class
8182
def get_code(self):
83+
''' returns the code of the current class '''
8284
import inspect
8385
return inspect.getsource(BinaryTree)
8486

@@ -91,35 +93,32 @@ def __init__(self, data):
9193
self._preorder = []
9294
self._postorder = []
9395

94-
# for setting left node
9596
def set_left(self, node):
97+
''' for setting the left child of the node '''
9698
self.leftChild = node
9799

98-
# for setting right node
99100
def set_right(self, node):
101+
''' for setting the right child of the node '''
100102
self.rightChild = node
101103

102-
# for getting the left node
103104
def get_left(self):
105+
''' returns the left child of the current node '''
104106
return self.leftChild
105107

106-
# for getting right node
107108
def get_right(self):
109+
''' returns the right child of the current node '''
108110
return self.rightChild
109111

110112
# for setting data of a node
111113
def set_data(self, data):
114+
''' for setting the data of a node '''
112115
self.data = data
113116

114117
# for getting data of a node
115118
def get_data(self):
119+
''' returns the data of the current node '''
116120
return self.data
117121

118-
# easily retrieve the source code of the Node class
119-
def get_code(self):
120-
import inspect
121-
return inspect.getsource(BSTNode)
122-
123122
def insert(self, data):
124123
''' For inserting the data in the Tree '''
125124
if self.data == data:
@@ -141,7 +140,7 @@ def insert(self, data):
141140
self.rightChild = BSTNode(data)
142141
return True
143142

144-
def minValueBSTNode(self, BSTNode):
143+
def min_val_bst_node(self, BSTNode):
145144
current = BSTNode
146145

147146
# loop down to find the leftmost leaf
@@ -173,7 +172,7 @@ def delete(self, data):
173172

174173
# deleting BSTNode with two children
175174
# first get the inorder successor
176-
temp = self.minValueBSTNode(self.rightChild)
175+
temp = self.min_val_bst_node(self.rightChild)
177176
self.data = temp.data
178177
self.rightChild = self.rightChild.delete(temp.data)
179178

@@ -228,6 +227,7 @@ def postorder(self, root):
228227

229228
# easily retrieve the source code of the BSTNode class
230229
def get_code(self):
230+
''' returns the code of current class '''
231231
import inspect
232232
return inspect.getsource(BSTNode)
233233

@@ -236,13 +236,15 @@ def __init__(self):
236236
self.root = None
237237

238238
def insert(self, data):
239+
''' inserts a node in the tree '''
239240
if self.root:
240241
return self.root.insert(data)
241242
else:
242243
self.root = BSTNode(data)
243244
return True
244245

245246
def delete(self, data):
247+
''' deletes the node with the specified data from the tree '''
246248
if self.root is not None:
247249
return self.root.delete(data)
248250

@@ -253,20 +255,24 @@ def find(self, data):
253255
return False
254256

255257
def preorder(self):
258+
''' finding the preorder of the tree '''
256259
if self.root is not None:
257260
return self.root.preorder(self.root)
258261

259262
def inorder(self):
263+
''' finding the inorder of the tree '''
260264
print()
261265
if self.root is not None:
262266
return self.root.inorder(self.root)
263267

264268
def postorder(self):
269+
''' finding the postorder of the tree '''
265270
print()
266271
if self.root is not None:
267272
return self.root.postorder(self.root)
268273

269274
# easily retrieve the source code of the BinarySearchTree class
270275
def get_code(self):
276+
''' returns the code of the current class '''
271277
import inspect
272278
return inspect.getsource(BinarySearchTree)

0 commit comments

Comments
 (0)