Treelib: rotace stromu
This commit is contained in:
parent
c1e107c89e
commit
0e2784d621
1 changed files with 46 additions and 0 deletions
|
@ -235,6 +235,52 @@ def swap_succ(node):
|
|||
# Dokumentace viz wiki:
|
||||
# (lower bude jednoduchá rotace, ne mega, existence jednoduché rotace mi došla až po nakreslení obrázku)
|
||||
def raise_node(node):
|
||||
if node is None:
|
||||
raise TreeLibError("Nelze přesunout None. Tohle by se nemělo stát.")
|
||||
# Pojmenování viz WIKI (as of 2020-03-19 01:33:44 GMT+1)
|
||||
# FIXME: Velmi naivní, chybí error checky
|
||||
D = node
|
||||
C = get_parent(D)
|
||||
E = C.succ
|
||||
subtree4_head = D.first_child
|
||||
subtree4_tail = last_brother(subtree4_head)
|
||||
subtree3P_head = D.succ
|
||||
subtree3L_head = C.first_child
|
||||
subtree3L_tail = safe_pred(D)
|
||||
|
||||
# Prostor pro motlitbu...
|
||||
pass
|
||||
|
||||
# Amen.
|
||||
C.succ = D
|
||||
C.save()
|
||||
D.succ = E
|
||||
D.save()
|
||||
subtree3L_tail.succ = None
|
||||
subtree3L_tail.save()
|
||||
subtree4_tail.succ = subtree3P.head
|
||||
subtree4_tail.save()
|
||||
|
||||
# To by mělo být všechno...
|
||||
|
||||
def lower_node(node):
|
||||
if node is None:
|
||||
raise TreeLibError("Nelze přesunout None. Tohle by se nemělo stát.")
|
||||
# Pojmenování viz WIKI (as of 2020-03-19 01:33:44 GMT+1)
|
||||
# FIXME: Velmi naivní, chybí error checky
|
||||
C = node
|
||||
D = C.succ
|
||||
B = safe_pred(C)
|
||||
subtree2_head = B.first_child
|
||||
subtree2_tail = last_brother(subtree2_head)
|
||||
|
||||
# Prostor pro motlitbu...
|
||||
pass
|
||||
|
||||
# Amen.
|
||||
B.succ = D
|
||||
B.save()
|
||||
subtree2_tail.succ = C
|
||||
subtree2_tail.save()
|
||||
|
||||
# To by mělo být všechno...
|
||||
|
|
Loading…
Reference in a new issue