diff --git a/BST.java b/BST.java index 75be4c6..f6ed692 100644 --- a/BST.java +++ b/BST.java @@ -65,17 +65,18 @@ public class BST { public String inOrder() { // TODO: implement this method using a non-recursive solution String return_string = ""; - BSTNode[] stack = new BSTNode[size()]; - int stack_pointer = 0; + Stack stack = new Stack(); BSTNode current = m_root; - while (true) { - while (current.getLeft() != null) { - stack[stack_pointer] = current; - stack_pointer++; + while ((current != null) || (stack.size() > 0)) { + while (current != null) { + stack.push(current); current = current.getLeft(); } + current = stack.pop(); + return_string += current.getInfo() + " "; + current = current.getRight(); } - return return_string; // replace this statement with your own return + return return_string; } // This method returns the smallest element in the binary search tree. You