(node,data)
| 120 | |
| 121 | |
| 122 | def insert_node(node,data): |
| 123 | if node is None: |
| 124 | return my_node(data) |
| 125 | if data < node.getdata(): |
| 126 | node.setleft(insert_node(node.getleft(),data)) |
| 127 | if getheight(node.getleft()) - getheight(node.getright()) == 2: #an unbalance detected |
| 128 | if data < node.getleft().getdata(): #new node is the left child of the left child |
| 129 | node = leftrotation(node) |
| 130 | else: |
| 131 | node = rlrotation(node) #new node is the right child of the left child |
| 132 | else: |
| 133 | node.setright(insert_node(node.getright(),data)) |
| 134 | if getheight(node.getright()) - getheight(node.getleft()) == 2: |
| 135 | if data < node.getright().getdata(): |
| 136 | node = lrrotation(node) |
| 137 | else: |
| 138 | node = rightrotation(node) |
| 139 | h1 = my_max(getheight(node.getright()),getheight(node.getleft())) + 1 |
| 140 | node.setheight(h1) |
| 141 | return node |
| 142 | |
| 143 | def getRightMost(root): |
| 144 | while root.getright() is not None: |
no test coverage detected