Program to insert item in tree, JAVA Programming

public class TreeTest
{
    public static void main(String args[])
    {
        Tree t = new Tree();
        System.out.println("Populating");
        t.insertItem(1);
        t.insertItem(2);
        t.insertItem(3);
        t.insertItem(4);
        t.insertItem(5);
        t.insertItem(6);

        printBreak(t);
        System.out.println("Balancing");
        t.balance();
        printBreak(t);
        System.out.println("Deleting 3");
        t.deleteItem(3);

        printBreak(t);
        System.out.println("Balancing");
        t.balance();
        printBreak(t);
        System.out.println("Populating");
        t.insertItem(12);
        t.insertItem(9);
        t.insertItem(13);
        t.insertItem(10);
        t.insertItem(11);
        t.insertItem(9);

        printBreak(t);
        System.out.println("Balancing");
        t.balance();
        printBreak(t);
        System.out.println("Deleting 11, 2, 10");
        t.deleteItem(11);
        t.deleteItem(2);
        t.deleteItem(10);
        printBreak(t);
        System.out.println("Balancing");
        t.balance();

        printBreak(t);
        
        System.out.print("Getting 13's node: ");
        TreeNode node = t.search(13);
        System.out.println(node.getData());

        System.out.printf("Tree currently has %d nodes\n", t.count());

        System.out.print("Looking for 10: ");
        if(t.findItem(10))
        {
            System.out.println("Found");
        }
        else
        {
            System.out.println("Not Found");
        }

        System.out.print("Looking for 9: ");
        if(t.findItem(9))
        {
            System.out.println("Found");
        }
        else
        {
            System.out.println("Not Found");
        }

        System.out.print("In Order: ");
        t.printInOrder();
        System.out.print("Pre Order: ");
        t.printPreOrder();
        System.out.print("Post Order: ");
        t.printPostOrder();
    }

    public static void printBreak(Tree t)
    {
        t.printTree();
        System.out.println("--------------------------------");
    }
}

Posted Date: 2/18/2013 4:24:40 AM | Location : United States







Related Discussions:- Program to insert item in tree, Assignment Help, Ask Question on Program to insert item in tree, Get Answer, Expert's Help, Program to insert item in tree Discussions

Write discussion on Program to insert item in tree
Your posts are moderated
Related Questions
Prompt the user for an int between an upper and lower boundary. Reuse the validateInput() method from project 2 to validate if the input is in bounds. If it is not, print an error

The project is optional. It is worth at least 7 bonus points beyond overall 100 points of this course. The grading will be on a pass/fail basis. Write a Java application (not ap

Normal 0 false false false EN-US X-NONE X-NONE

Question: (a) Draw out a UML class diagram that captures the following information: An Employee is a kind of Person. An ATM is a kind of Machine. Both an Employee and an ATM

hi,i need whatsapp panel to send unlimitd message. skype : maya123.com email :

Elaborate with examples Vector or Object oriented graphics? Vector or Object-Oriented Graphics treats everything which is drawn as an object. Objects retain their identity afte

Project Description: Overview I am seeking an Oracle ADF mobile app and web service to be created that takes a list of contacts stored on an Android mobile phone or tablet an

How can i draw E-R diagram

Using the above thread program, now create 20 threads in your program and run them. No need to wait for the keyboard in each thread, just print "Hello" and its thread id in each t

Want to Design an all encompassing Database for a small business Project Description: I want to organize and structure an all encompassing database and Information management