(root,data)
| 150 | return root.getdata() |
| 151 | |
| 152 | def del_node(root,data): |
| 153 | if root.getdata() == data: |
| 154 | if root.getleft() is not None and root.getright() is not None: |
| 155 | temp_data = getLeftMost(root.getright()) |
| 156 | root.setdata(temp_data) |
| 157 | root.setright(del_node(root.getright(),temp_data)) |
| 158 | elif root.getleft() is not None: |
| 159 | root = root.getleft() |
| 160 | else: |
| 161 | root = root.getright() |
| 162 | elif root.getdata() > data: |
| 163 | if root.getleft() is None: |
| 164 | print("No such data") |
| 165 | return root |
| 166 | else: |
| 167 | root.setleft(del_node(root.getleft(),data)) |
| 168 | elif root.getdata() < data: |
| 169 | if root.getright() is None: |
| 170 | return root |
| 171 | else: |
| 172 | root.setright(del_node(root.getright(),data)) |
| 173 | if root is None: |
| 174 | return root |
| 175 | if getheight(root.getright()) - getheight(root.getleft()) == 2: |
| 176 | if getheight(root.getright().getright()) > getheight(root.getright().getleft()): |
| 177 | root = rightrotation(root) |
| 178 | else: |
| 179 | root = lrrotation(root) |
| 180 | elif getheight(root.getright()) - getheight(root.getleft()) == -2: |
| 181 | if getheight(root.getleft().getleft()) > getheight(root.getleft().getright()): |
| 182 | root = leftrotation(root) |
| 183 | else: |
| 184 | root = rlrotation(root) |
| 185 | height = my_max(getheight(root.getright()),getheight(root.getleft())) + 1 |
| 186 | root.setheight(height) |
| 187 | return root |
| 188 | |
| 189 | class AVLtree: |
| 190 | def __init__(self): |
no test coverage detected