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
Explain Subclasses and Polymorphism ? Car and Motorcycle are subclasses of MotorVehicle. If you instantiate a Car or a Motorcycle along with new, you can use in which object a

Need iOS native App Developer Project Description: I want someone to help me prepare a simple inventory system. I am not a programmer trying to learn as i go. Skills re

could you please help me with my assignment. My program need to implement a multi{level role based database script SQL-like generation program. Or part of one anyway. Start with a

Question 1: a) What is an "Operating System"? b) Describe the four main computer system components. c) Describe and compare "Parallel Systems" and "Distributed Systems

Project Description: I want to build a camera application for android. By default android will add metadata for the image, for e.g.  Date, time, resolution, gps tag etc..In this

Extend the given drawing program (the version that allows undo and redo) as follows: a) Allow the user to select font and font size; user should also be able to boldface, underl

An application server cluster has of a number of application servers loosely coupled on a network. The server group or server cluster is usually distributed over a number of nodes

Suppose that: A is the set of characters in the string "pellet"; B is the set of characters in the string "teller"; C is the set of characters in the string "pertinent"; a

Payroll Calculator for Both Hourly and Commission Employees In assignment 13, we will create a payroll calculator that calculates   gross pay ,   taxes , and   net pay   fo

Write a program on Filling Rectangles ? The drawRect() method draws an open rectangle, a box if you prefer. If you need to draw a filled rectangle, use the fillRect() method. O