@Test public void postorderTraversalTest(){ TreeSearch<Integer> treeSearch = new TreeSearch<Integer>(); Integer value = 5; String expectedSearchPath = "8->4->5"; treeSearch.postorderTraversal(root, value); Assert.assertTrue(expectedSearchPath.equals(treeSearch.searchPath.toString())); treeSearch = new TreeSearch<Integer>(); value = 6; expectedSearchPath = "8->4->5->2->6"; treeSearch.postorderTraversal(root, value); Assert.assertTrue(expectedSearchPath.equals(treeSearch.searchPath.toString())); }
public void postorderTraversal(TreeNode<T> root, T data){ if(root == null){ return; } if(!isSearched) postorderTraversal(root.left, data); if(!isSearched) postorderTraversal(root.right, data); if(!isSearched){ if(!searchPath.toString().equals("")){ searchPath.append("->"); } searchPath.append(root.data); if(root.data.equals(data)) isSearched = true; } }
TreeSearch { public void postorderTraversal(TreeNode<T> root, T data){ if(root == null){ return; } if(!isSearched) postorderTraversal(root.left, data); if(!isSearched) postorderTraversal(root.right, data); if(!isSearched){ if(!searchPath.toString().equals("")){ searchPath.append("->"); } searchPath.append(root.data); if(root.data.equals(data)) isSearched = true; } } }
TreeSearch { public void postorderTraversal(TreeNode<T> root, T data){ if(root == null){ return; } if(!isSearched) postorderTraversal(root.left, data); if(!isSearched) postorderTraversal(root.right, data); if(!isSearched){ if(!searchPath.toString().equals("")){ searchPath.append("->"); } searchPath.append(root.data); if(root.data.equals(data)) isSearched = true; } }  }
TreeSearch { public void postorderTraversal(TreeNode<T> root, T data){ if(root == null){ return; } if(!isSearched) postorderTraversal(root.left, data); if(!isSearched) postorderTraversal(root.right, data); if(!isSearched){ if(!searchPath.toString().equals("")){ searchPath.append("->"); } searchPath.append(root.data); if(root.data.equals(data)) isSearched = true; } }  void preorderTraversal(TreeNode<T> root, T data); void inorderTraversal(TreeNode<T> root, T data); void postorderTraversal(TreeNode<T> root, T data); }
TreeSearch { public void postorderTraversal(TreeNode<T> root, T data){ if(root == null){ return; } if(!isSearched) postorderTraversal(root.left, data); if(!isSearched) postorderTraversal(root.right, data); if(!isSearched){ if(!searchPath.toString().equals("")){ searchPath.append("->"); } searchPath.append(root.data); if(root.data.equals(data)) isSearched = true; } }  void preorderTraversal(TreeNode<T> root, T data); void inorderTraversal(TreeNode<T> root, T data); void postorderTraversal(TreeNode<T> root, T data);  }