Because if head == root, there wasn't a left side to do. Look up three lines.
Because if head == root, there wasn't a left side to do. Look up three lines.
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);
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
head equals root only once in the most left node (the smallest)
we dont want it to run on this case
thanks
where can i find a tutorial on binary tree recursion
i searched in google:
and there is no tutorials for this kind of stuffCode:http://www.google.co.il/search?hl=iw&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=binary+tree+recursion&spell=1
??
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
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.