搜索此博客

2011年2月23日星期三

Convert a binary search tree into sorted double link list

For example, binary search tree
10
/ \
6 14
/\ /\
4 8 12 16
into double link list:
4=6=8=10=12=14=16

Idea:
The basic idea is that we can get the sorted the elements in the tree by in-order traveling. When we visit one node, we can put this node into the double link list. After traveling the whole tree, we can get a sorted double link list.

The code is as follows:

没有评论:

发表评论