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
Compare classes with C++ Some significant points to consider when defining a class in java as you probably noticed from above given skeleton are -  There  are  no  global

How many ways are there to call a function in a program? Explain with example? Two Ways of Calling Functions: Functions do not run automatically. While the page loads, every

What are adding methods? A subclass isn't restricted to changing the behavior of its superclass. It can also add fully latest techniques and fields that are not shared along wi

Outbound Submissions and Tracking: Project Overview: In the current ARISg environment, expedited reports are qualified and distributed electronically to contacts maintaine

In addition to your Java code requirements, you also need to enhance the ZHTML for your application. As before, you can continue working with the page(s) you used for the previous

What is casting? There are two types of casting, casting among primitive numeric types and casting among object references. Casting among numeric types is used to convert large

The Java programming language is object-oriented and includes automatic garbage collection. Garbage collection is the process of reclaiming memory taken up by unreferenced objects.

write a java program to test for class Person Student faculty Employee

How can we include images in a web page using HTML and Java script? Image in HTML Image in Javascript Images in JavaScript could be manipulated in several ways using the buil

You can declare a variable by the var statement such as: var strname = some value You can also declare a variable with simply assigning a value to the variable. Although, if