package program12;
import java.io.*;
public class Main
{
// Program #12
// Zach Krizan
// Data Structures
public static void main(String[] args) throws IOException {
/*********************************************************************
* This program will demonstrate deleting from a tree with 2 children.
* It will insert 7 numbers into the tree.
* Then it will traverse the tree in in-order.
* It will then display the visual of the tree.
* Next it will display a message and delete value 6.
* Then it will traverse the tree and display the tree.
* When it displays the the visual of the tree, it will use a'0' in
* place of the deleted value.
**********************************************************************/
Tree theTree = new Tree(); //tree object
//runs method insert() with numbers 1-7
System.out.println("Inserting...");
theTree.insert(4);
theTree.insert(2);
theTree.insert(6);
theTree.insert(1);
theTree.insert(3);
theTree.insert(5);
theTree.insert(7);
System.out.println("The values inserted are 4,2,6,1,3,5,7");
System.out.println();
System.out.println("Displaying Tree:");
theTree.displayTree(); //runs method displayTree()
System.out.println("Traversing...");
theTree.traverse(); //runs method traverse()
/*************************************
* Deleting Value 6
**************************************/
System.out.println();
System.out.println("+-----------------------------+");
System.out.println("Deleting value '6'...");
System.out.println("+-----------------------------+");
theTree.delete(6); //runs method delete()
System.out.println();
System.out.println("Traversing...");
theTree.traverse(); //runs method traverse()
System.out.println();
System.out.println();
System.out.println("Deleted values will be " +
"replaced by '0'");
System.out.println();
System.out.println("Displaying Tree:");
theTree.displayTree(); //runs method displayTree()
System.out.println("Program will now end");
System.exit(0);
} //end main
} //end Main
/********************************
*
* Same 2 & 3 as 11
*
********************************/
No comments:
Post a Comment