4 Replies Latest reply: Oct 8, 2007 1:02 AM by 807600 RSS

    recursion problems

      So i have a little problem. Im writing a method that will go though a binary search tree and print out all the nodes in the tree in the pattern of an inorder traversal. What it is supposed to do is print out 3 things, the element in the node, its number in the inorder sequence, and the depth of that particular node. Everything works except the part where i need to print the inorder value of the node. How can i get a value to be printed out at the same time as the recursive call (like a counter) but without actually being part of the recursive call (which would lead to the counter going up or down depending on how many calls the method has gone through)? i would post my code but i do know that several people in my class look at this site frequently and i would rather not let them slack and use my work. If what i said was confusing post back and i will try to be more clear. thanks for the help!

      -hopefully_learning :P
        • 1. Re: recursion problems
          the inorder value of the node
          Are you reffering to the # of the node in the tree in your traversal? Or the actual value in the Node, like to be printed from a toString() method?
          • 2. Re: recursion problems
            the actual # of the node in the traversal. I have another method that can return the value stored inside the node.
            • 3. Re: recursion problems
              You will need an instance variable that keeps track of which node you are up to.
              • 4. Re: recursion problems
                Is that an instance variable that keeps track of my relative position in the tree? im a little confused as to why you would need one as if i want to know where i am i can just look at my "root" for the particular sub tree i happen to be at. Unless you mean which node in the traversal i am up to. Then i can only increment when i get to a node i haven't gotten to yet i suppose. Sorry im being so dense with this. :P