Exemplo n.º 1
0
 private void postOrder(Node localRoot) {
   if (localRoot != null) {
     postOrder(localRoot.leftChild);
     postOrder(localRoot.rightChild);
     localRoot.displayNode();
   }
 }
Exemplo n.º 2
0
  public static void main(String[] args) {
    LinkedList yes = new LinkedList();
    Node A = yes.add(4);
    yes.add(3);
    yes.add(5);
    yes.add(1);
    yes.add(8);
    Node B = yes.add(2);
    // yes.printBackwards(B);

    Queue yes2 = new Queue();
    Node C = yes2.enqueue(4);
    yes2.enqueue(3);
    yes2.enqueue(5);
    yes2.enqueue(1);
    yes2.enqueue(8);
    yes2.dequeue();
    yes2.dequeue();
    int m = yes2.peek();
    // System.out.println(m);

    Stack yes3 = new Stack();
    Node D = yes3.push(3);
    yes3.push(5);
    yes3.push(6);
    yes3.push(1);
    yes3.push(8);
    /*int p = yes3.peek();
    System.out.println(p);
    yes3.pop();
    p = yes3.peek();
    System.out.println(p);
    yes3.pop();
    p = yes3.peek();
    System.out.println(p);
    yes3.pop();
    p = yes3.peek();
    System.out.println(p);
    yes3.pop();
    p = yes3.peek();
    System.out.println(p);*/

    Tree yes4 = new Tree();
    TreeNode E = yes4.add(5);
    yes4.add(3);
    yes4.add(7);
    yes4.add(1);
    yes4.add(9);

    yes4.inOrder(E);
    yes4.preOrder(E);
    yes4.postOrder(E);
  }
Exemplo n.º 3
0
 public void traverse(int type) {
   switch (type) {
     case 1:
       System.out.print("Preorder Traversal:-    ");
       preOrder(root);
       break;
     case 2:
       System.out.print("Inorder Traversal:-     ");
       inOrder(root);
       break;
     case 3:
       System.out.print("Postorder Traversal:-   ");
       postOrder(root);
       break;
     default:
       System.out.println("Invalid Choice");
   }
 }