@@ -8,32 +8,33 @@ def __init__(self, data = None):
8
8
self .right = None
9
9
self .data = data
10
10
11
- # for setting left node
12
11
def set_left (self , node ):
12
+ ''' for setting the left child of the node '''
13
13
self .left = node
14
14
15
- # for setting right node
16
15
def set_right (self , node ):
16
+ ''' for setting the right child of the node '''
17
17
self .right = node
18
18
19
- # for getting the left node
20
19
def get_left (self ):
20
+ ''' for getting the left child of the node '''
21
21
return self .left
22
22
23
- # for getting right node
24
23
def get_right (self ):
24
+ ''' for getting the right child of the node '''
25
25
return self .right
26
26
27
- # for setting data of a node
28
27
def set_data (self , data ):
28
+ ''' for setting the data of the node '''
29
29
self .data = data
30
30
31
- # for getting data of a node
32
31
def get_data (self ):
32
+ ''' for getting the data of the node '''
33
33
return self .data
34
34
35
35
# easily retrieve the source code of the Node class
36
36
def get_code (self ):
37
+ ''' returns the code of the current class '''
37
38
import inspect
38
39
return inspect .getsource (Node )
39
40
@@ -79,6 +80,7 @@ def postorder(self, root):
79
80
80
81
# easily retrieve the source code of the BinaryTree class
81
82
def get_code (self ):
83
+ ''' returns the code of the current class '''
82
84
import inspect
83
85
return inspect .getsource (BinaryTree )
84
86
@@ -91,35 +93,32 @@ def __init__(self, data):
91
93
self ._preorder = []
92
94
self ._postorder = []
93
95
94
- # for setting left node
95
96
def set_left (self , node ):
97
+ ''' for setting the left child of the node '''
96
98
self .leftChild = node
97
99
98
- # for setting right node
99
100
def set_right (self , node ):
101
+ ''' for setting the right child of the node '''
100
102
self .rightChild = node
101
103
102
- # for getting the left node
103
104
def get_left (self ):
105
+ ''' returns the left child of the current node '''
104
106
return self .leftChild
105
107
106
- # for getting right node
107
108
def get_right (self ):
109
+ ''' returns the right child of the current node '''
108
110
return self .rightChild
109
111
110
112
# for setting data of a node
111
113
def set_data (self , data ):
114
+ ''' for setting the data of a node '''
112
115
self .data = data
113
116
114
117
# for getting data of a node
115
118
def get_data (self ):
119
+ ''' returns the data of the current node '''
116
120
return self .data
117
121
118
- # easily retrieve the source code of the Node class
119
- def get_code (self ):
120
- import inspect
121
- return inspect .getsource (BSTNode )
122
-
123
122
def insert (self , data ):
124
123
''' For inserting the data in the Tree '''
125
124
if self .data == data :
@@ -141,7 +140,7 @@ def insert(self, data):
141
140
self .rightChild = BSTNode (data )
142
141
return True
143
142
144
- def minValueBSTNode (self , BSTNode ):
143
+ def min_val_bst_node (self , BSTNode ):
145
144
current = BSTNode
146
145
147
146
# loop down to find the leftmost leaf
@@ -173,7 +172,7 @@ def delete(self, data):
173
172
174
173
# deleting BSTNode with two children
175
174
# first get the inorder successor
176
- temp = self .minValueBSTNode (self .rightChild )
175
+ temp = self .min_val_bst_node (self .rightChild )
177
176
self .data = temp .data
178
177
self .rightChild = self .rightChild .delete (temp .data )
179
178
@@ -228,6 +227,7 @@ def postorder(self, root):
228
227
229
228
# easily retrieve the source code of the BSTNode class
230
229
def get_code (self ):
230
+ ''' returns the code of current class '''
231
231
import inspect
232
232
return inspect .getsource (BSTNode )
233
233
@@ -236,13 +236,15 @@ def __init__(self):
236
236
self .root = None
237
237
238
238
def insert (self , data ):
239
+ ''' inserts a node in the tree '''
239
240
if self .root :
240
241
return self .root .insert (data )
241
242
else :
242
243
self .root = BSTNode (data )
243
244
return True
244
245
245
246
def delete (self , data ):
247
+ ''' deletes the node with the specified data from the tree '''
246
248
if self .root is not None :
247
249
return self .root .delete (data )
248
250
@@ -253,20 +255,24 @@ def find(self, data):
253
255
return False
254
256
255
257
def preorder (self ):
258
+ ''' finding the preorder of the tree '''
256
259
if self .root is not None :
257
260
return self .root .preorder (self .root )
258
261
259
262
def inorder (self ):
263
+ ''' finding the inorder of the tree '''
260
264
print ()
261
265
if self .root is not None :
262
266
return self .root .inorder (self .root )
263
267
264
268
def postorder (self ):
269
+ ''' finding the postorder of the tree '''
265
270
print ()
266
271
if self .root is not None :
267
272
return self .root .postorder (self .root )
268
273
269
274
# easily retrieve the source code of the BinarySearchTree class
270
275
def get_code (self ):
276
+ ''' returns the code of the current class '''
271
277
import inspect
272
278
return inspect .getsource (BinarySearchTree )
0 commit comments