Subj : Re: Recursion in Java: Question for those who understand recursion well. To : comp.programming From : CBFalconer Date : Sat Aug 27 2005 08:34 am Casey Hawthorne wrote: (carelessly neglecting to include context) > success_ny@yahoo.com wrote: (which I have reinserted) >> >> I have a tree represented as a linked list of simple objects >> (nodeId/parentId pairs) where the root node is the 1st element in >> the list. The other nodes are in somewhat random order. The >> parentId refers to the parent node. >> >> I want to convert it into a list where the values are in pre-order. >> I.e., I want to get this list as follows: ABCDEFGHIJ (see graph >> below). I.e., get the 1st node, put in in the list. If it has >> children, go through them one by one, get their child nodes, then >> put the parent in the list, then the leftmost first, and go from >> there. I.e., so that it's ordered in my linked list like this by >> (letters represent nodeId): >> >> A >> / \ >> B J >> / | \ >> C H I >> | >> D >> /|\ >> E F G >> .... snip code ... >> >> Any idea what the problem is? > > You are doing preorder traversal. > > preorder(tree) > begin > if tree is null, return; > > print(tree.root); > preorder(tree.left_subtree); > preorder(tree.right_subtree); > end No he isn't. What he has shown is not a binary tree. Even if it was, he would want an inorder traversal. He neglected to show the declarations for the actual tree. For help, the OP should post a complete compilable minimized program. -- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson .