Java – a non recursive method for calculating a binary tree representing an arithmetic expression
As mentioned in the topic, I need to describe a method for evaluating binary arithmetic expression trees without recursion Did not give me any other details or instructions
As for my understanding of these things, I need to simulate the sequential traversal of the tree Assuming that my textbook outlines the availability of ADT methods, I have hasleft(), hasright(), left(), right(), isinternal() and isexternal() methods I need to ask my professor if I can create my own method, but I don't use the parent () method, so I can traverse the tree Although, I have a root () method
Someone might point me in the right direction to figure out how to do this? I didn't think there was no recursive method, because I didn't have a way to jump back to the tree immediately
resolvent
Solution
You can keep a bunch of nodes that have been accessed Then the recursive call is replaced by pushing the new node onto the stack, and a node returning the recursive function is popped from the stack
Remember, when executing recursive functions, there is always an implicit stack to remember the parameters passed in each function call