Interview Practice 01 – Convert Binary Tree into Doubly Linked List

Question

Convert binary search tree into doubly linked list. It’s required not to create any new node, but only turning pointers.

Solution

The following shows the concept of this question.

8
/
6 0 -> 5 = 6 = 7 = 8 = 9 = 0 = 1
/ /
5 7 9 1

First, since node for both binary tree and doubly linked list have left and right node, they can use the same node structure. Then, looking the doubly linked list as a normal linked list, it is actually a in-order depth-first traversal result.