3622
правки
Изменения
Rope
,→Псевдокод
'''Pair'''<Node, Node> split(Node node, '''int''' i):
Node tree1, tree2
'''if''' node.left <tex>\ne \varnothing</tex>
'''if''' node.left.w >= i
tree2.left = res.second
tree2.right = node.right
tree2.w = tree2.left.w + tree2.right.w
'''else'''
'''Pair''' res = split(node.right, i - node.left.w)
tree1.left = node.left
tree1.right = res.first
tree1.w = tree1.left.w + tree1.right.w
tree2 = res.second
'''else'''
tree1.s = node.s.substr(0, i)
tree2.s = node.s.substr(i, node.s.len) tree1.w = i tree2.w = node.s.len - i
'''return''' '''Pair'''(tree1, tree2)