# Thread: changing a tree into a list question..

1. Because if head == root, there wasn't a left side to do. Look up three lines.

2. 1. List-ify the left half of the tree.
2. List-ify the right half of the tree.
3. Link the rightmost element of the left half to the root.
4. Link the root to the leftmost element of the right half.
5. Done.

The special cases are where the left or right halves are empty lists.

The following prototype may inspire you:

Code:
`void *tree2list_helper(node *root, node **head, node **tail);`

3. head equals root only once in the most left node (the smallest)

we dont want it to run on this case

thanks

4. Originally Posted by transgalactic2
head equals root only once in the most left node (the smallest)

we dont want it to run on this case

thanks
head equals root for every node that doesn't have a left child. (Notice that root is the parameter to the function, not the actual root of the tree.)

5. where can i find a tutorial on binary tree recursion

i searched in google:
Code:
`http://www.google.co.il/search?hl=iw&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=binary+tree+recursion&spell=1`
and there is no tutorials for this kind of stuff

??

6. The problem is perhaps that recursion wasn't part of the subject, but the tutorial here on Cprogramming about binary trees is using recursion:
http://www.cprogramming.com/tutorial/lesson18.html

--
Mats

Popular pages Recent additions