MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / leftrotation

Function leftrotation

data_structures/binary tree/AVLtree.py:67–87  ·  view source on GitHub ↗

r''' A B / \ / \ B C Bl A / \ --> / / \ Bl Br UB Br C / UB UB = unbalanced node

(node)

Source from the content-addressed store, hash-verified

65
66
67def leftrotation(node):
68 r'''
69 A B
70 / \ / \
71 B C Bl A
72 / \ --> / / \
73 Bl Br UB Br C
74 /
75 UB
76
77 UB = unbalanced node
78 '''
79 print("left rotation node:",node.getdata())
80 ret = node.getleft()
81 node.setleft(ret.getright())
82 ret.setright(node)
83 h1 = my_max(getheight(node.getright()),getheight(node.getleft())) + 1
84 node.setheight(h1)
85 h2 = my_max(getheight(ret.getright()),getheight(ret.getleft())) + 1
86 ret.setheight(h2)
87 return ret
88
89def rightrotation(node):
90 '''

Callers 4

rlrotationFunction · 0.85
lrrotationFunction · 0.85
insert_nodeFunction · 0.85
del_nodeFunction · 0.85

Calls 8

my_maxFunction · 0.85
getheightFunction · 0.85
getdataMethod · 0.80
getleftMethod · 0.80
setleftMethod · 0.80
getrightMethod · 0.80
setrightMethod · 0.80
setheightMethod · 0.80

Tested by

no test coverage detected