MCPcopy Index your code
hub / github.com/subbarayudu-j/TheAlgorithms-Python / AVLtree

Class AVLtree

data_structures/binary tree/AVLtree.py:189–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187 return root
188
189class AVLtree:
190 def __init__(self):
191 self.root = None
192 def getheight(self):
193# print("yyy")
194 return getheight(self.root)
195 def insert(self,data):
196 print("insert:"+str(data))
197 self.root = insert_node(self.root,data)
198
199 def del_node(self,data):
200 print("delete:"+str(data))
201 if self.root is None:
202 print("Tree is empty!")
203 return
204 self.root = del_node(self.root,data)
205 def traversale(self): #a level traversale, gives a more intuitive look on the tree
206 q = my_queue()
207 q.push(self.root)
208 layer = self.getheight()
209 if layer == 0:
210 return
211 cnt = 0
212 while not q.isEmpty():
213 node = q.pop()
214 space = " "*int(math.pow(2,layer-1))
215 print(space,end = "")
216 if node is None:
217 print("*",end = "")
218 q.push(None)
219 q.push(None)
220 else:
221 print(node.getdata(),end = "")
222 q.push(node.getleft())
223 q.push(node.getright())
224 print(space,end = "")
225 cnt = cnt + 1
226 for i in range(100):
227 if cnt == math.pow(2,i) - 1:
228 layer = layer -1
229 if layer == 0:
230 print()
231 print("*************************************")
232 return
233 print()
234 break
235 print()
236 print("*************************************")
237 return
238
239 def test(self):
240 getheight(None)
241 print("****")
242 self.getheight()
243if __name__ == "__main__":
244 t = AVLtree()
245 t.traversale()

Callers 1

AVLtree.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected