select(A, p, r, i)
{
if (p = r) then return A[p];
mid = median(A, p, r);
q = partition(A, p, r, mid);
k = q - p + 1;
if (i <= q) return select(A, p, q, i);
else return select(A, q+1, r, i-k);
}
In the following function head(h) returns the head (think it as a pointer) of h, left(h) and right(h) return the left and right subtrees of h respectively. @ is concatenation operator on lists.
function list (h)
return if h == nil then []
else if h <> nil and head(h) is not marked 'deleted' then [h]
else if h <> nil and head(h) is marked 'deleted'
then list(left(h))@list(right(h))