| dll_to_bst_rec#(head, n; h; root, right) {if n > 0 then {let m = n / 2, left = null in {dll_to_bst_rec#(head, m; h; left, root); h[root].left := left}; let m = n - n / 2 - 1, temp = null, next = h[root].right in {dll_to_bst_rec#(next, m; h; temp, right); h[root].right := temp}} else {root := null; right := head} } |