r''' A B / \ / \ B C Bl A / \ --> / / \ Bl Br UB Br C / UB UB = unbalanced node
(node)
| 65 | |
| 66 | |
| 67 | def 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 | |
| 89 | def rightrotation(node): |
| 90 | ''' |
no test coverage detected