partition(tree,i):
| Input tree with n nodes, index i
| Output tree with item #i moved to the root
|
| m=#nodes(left(tree))
| if i < m then
| left(tree)=partition(left(tree),i)
| tree=rotateRight(tree)
| else if i > m then
| right(tree)=partition(right(tree),i-m-1)
| tree=rotateLeft(tree)
| end if
| return tree
|