ListCell* mems(const Node* T, ListCell* L) { if(T == NULL) { return L; } else { ListCell* B = mems(T->right, L); ListCell* A = mems(T->left, B); return cons(T->item, A); } }
Look at the example where L is [4, 5, 6] and T is
you know that the answer is [9, 2, 0, 7, 1, 8, 4, 5, 6].
List B is [7, 1, 8, 4, 5, 6], the list of all members of the right subtree of T followed by L.
List A is [2, 0, 7, 1, 8, 4, 5, 6], the list of all members of the left subtree of T followed by B.
The result is 9:A = [9, 2, 0, 7, 1, 8, 4, 5, 6].