Program to insert item in tree, JAVA Programming

Assignment Help:

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("--------------------------------");
    }
}


Related Discussions:- Program to insert item in tree

Javascript and coldfusion, Overview Demonstrate your knowledge of JavaS...

Overview Demonstrate your knowledge of JavaScript and ColdFusion by implementing the following functionality: Contact form • The following validation error message shou

Big m method, i''ve done an application that calculates simplex methods i n...

i''ve done an application that calculates simplex methods i need to add big m method can any one help me?

War file for your application that can be deployed on tomcat, Deliverable: ...

Deliverable:  1) WAR file for your application that can be deployed and run on TomcaT (War file must contains the Java source code) Requirement for application: 1. Application m

Explain what occur when an object is created in java, Explain what occur wh...

Explain what occur when an object is created in Java?

write program a, How do I write a program a bout Rotor cipher

How do I write a program a bout Rotor cipher?

Activity diagram, The statechart diagrams and activity diagram are related ...

The statechart diagrams and activity diagram are related in a sense that statechart diagram refers on object undergoing a transition process and an activity diagram refers on the f

Beam, program for hinged beam

program for hinged beam

Explain the for loop in java, Explain the for loop in java? // This is ...

Explain the for loop in java? // This is the Hello program in Java class Hello { public static void main (String args[]) { System.out.print("Hello "); // Say Hello

It, Implement a program that can compute your taxes (assume year 2012, as- ...

Implement a program that can compute your taxes (assume year 2012, as- sume a form 1040EZ). The form should ask for your ling status (single, married), income, deductions and cred

Explain the term naming packages in details, Explain the term Naming Packag...

Explain the term Naming Packages in details? As you saw previously name space conflicts arise if two pieces of code declare the similar name. Java remains track of what belongs

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd