Showing posts with label Binary Tree with Traversels– InOrder PreOrder PostOrder – (Recursive and Non-Recursive). Show all posts
Showing posts with label Binary Tree with Traversels– InOrder PreOrder PostOrder – (Recursive and Non-Recursive). Show all posts

Saturday, April 16, 2011

Binary Tree with Traversels– InOrder, PreOrder, PostOrder – (Recursive& Non-Recursive)


import java.util.Scanner;
import java.util.Stack;

public class Node
{
    int info;
    Node next,prev;
    Node left,right;
}

public class BinaryTree
{
    Node Insert(int val)
    {
        Node t=new Node();
        t.info=val;
        return(t);
    }
    void setLeft(Node p,int val)
    {
        if(p==null || p.left!=null)
            System.out.println("\nInvalid Insertion");
        else
            p.left=Insert(val);
    }
    void setRight(Node p,int val)
    {
        if(p==null || p.right!=null)
            System.out.println("\nInvalid insertion");
        else
            p.right=Insert(val);
    }
    void InRecur(Node Start)
    {