Source of TreeTest.java


  1: // Fig. 17.18: TreeTest.java
  2: // This program tests class Tree.
  3: import java.util.Random;
  4: import com.deitel.jhtp6.ch17.Tree;
  5: 
  6: public class TreeTest 
  7: {
  8:    public static void main( String args[] )
  9:    {
 10:       Tree tree = new Tree();
 11:       int value;
 12:       Random randomNumber = new Random();
 13: 
 14:       System.out.println( "Inserting the following values: " );
 15: 
 16:       // insert 10 random integers from 0-99 in tree 
 17:       for ( int i = 1; i <= 10; i++ ) 
 18:       {
 19:          value = randomNumber.nextInt( 100 );
 20:          System.out.print( value + " " );
 21:          tree.insertNode( value );
 22:       } // end for
 23: 
 24:       System.out.println ( "\n\nPreorder traversal" );
 25:       tree.preorderTraversal(); // perform preorder traversal of tree
 26: 
 27:       System.out.println ( "\n\nInorder traversal" );
 28:       tree.inorderTraversal(); // perform inorder traversal of tree
 29: 
 30:       System.out.println ( "\n\nPostorder traversal" );
 31:       tree.postorderTraversal(); // perform postorder traversal of tree
 32:       System.out.println();
 33:    } // end main
 34: } // end class TreeTest
 35: 
 36: 
 37: /**************************************************************************
 38:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 39:  * Pearson Education, Inc. All Rights Reserved.                           *
 40:  *                                                                        *
 41:  * DISCLAIMER: The authors and publisher of this book have used their     *
 42:  * best efforts in preparing the book. These efforts include the          *
 43:  * development, research, and testing of the theories and programs        *
 44:  * to determine their effectiveness. The authors and publisher make       *
 45:  * no warranty of any kind, expressed or implied, with regard to these    *
 46:  * programs or to the documentation contained in these books. The authors *
 47:  * and publisher shall not be liable in any event for incidental or       *
 48:  * consequential damages in connection with, or arising out of, the       *
 49:  * furnishing, performance, or use of these programs.                     *
 50:  *************************************************************************/