Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.13 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package forestanalyzer;
  7. import java.io.FileReader;
  8. import java.io.IOException;
  9. import java.io.PrintStream;
  10. import java.util.Scanner;
  11. import java.util.function.Function;
  12.  
  13. /**
  14.  * Performs insertions and searches, using the same data set,on a binary search
  15.  * tree and an AVL tree to compare the performance of
  16.  * these operations on the trees.
  17.  * @author Duncan, Noah Gothreaux
  18.  * @SEE AVLTree, AVLTreeException, BSTree, BSTreeException,
  19.  * @since DATE LAST MODIFIED
  20.  */
  21. public class ForestAnalyzer
  22. {
  23.     /**
  24.      * @param args the command line arguments
  25.      * @throws AVLTreeException
  26.      * @throws BSTreeException
  27.      * @throws java.io.IOException
  28.      */
  29.     public static void main(String[] args) throws AVLTreeException, BSTreeException, IOException
  30.     {      
  31.         AVLTree yeetAVL=new AVLTree();
  32.         BSTree yeetBS=new BSTree();
  33.         Scanner yeetScan = new Scanner(new FileReader(args[0]));
  34.         Function<String, PrintStream> halfLifeYeet = x ->
  35.                 {
  36.                     System.out.printf("%-20s%n",x);
  37.                     return null;
  38.                 };
  39.     String command;
  40.     String yeetTemp;
  41.         while(yeetScan.hasNext())
  42.         {
  43.             if(command.equalsIgnoreCase("insert"))
  44.             {
  45.         yeetTemp = yeetScan.next()
  46.         yeetAVL.insert(yeetTemp);
  47.         yeetBS.insert(yeetTemp);               
  48.                 System.out.printf("inserted: %s in the AVL%n"
  49.                         + "inserted: %s in the BST%n"
  50.                         + "Type: size    height   diameter   full?    perfect?%n"
  51.                         + "AVL:   %d       %d        %d        %b      %b%n"
  52.                         + "BST:   %d       %d        %d        %b      %b%n"
  53.                         ,tempYeet,tempYeet,yeetAVL.size(),yeetAVL.height(),yeetAVL.diameter(),
  54.                         yeetAVL.isFull(),yeetAVL.isPerfect(),yeetBS.size(),yeetBS.height(),
  55.                         yeetBS.diameter(),yeetBS.isFull(),yeetBS.isPerfect());
  56.             }
  57.             if(command.equalsIgnoreCase("remove"))
  58.             {
  59.         yeetTemp = yeetScan.next()
  60.         yeetAVL.remove(yeetTemp);
  61.         yeetBS.remove(yeetTemp);
  62.                 System.out.printf("removed: %s in the AVL%n"
  63.                         + "removed: %s in the BST%n"
  64.                         + "Type: size    height   diameter   full?    perfect?%n"
  65.                         + "AVL:   %d       %d        %d        %b      %b%n"
  66.                         + "BST:   %d       %d        %d        %b      %b%n"
  67.                         ,tempYeet,tempYeet,yeetAVL.size(),yeetAVL.height(),yeetAVL.diameter(),
  68.                         yeetAVL.isFull(),yeetAVL.isPerfect(),yeetBS.size(),yeetBS.height(),
  69.                         yeetBS.diameter(),yeetBS.isFull(),yeetBS.isPerfect());
  70.             }
  71.             if(command.equalsIgnoreCase("traverse"))
  72.             {
  73.                 yeetAVL.traverse(halfLifeYeet);
  74.                 yeetBS.traverse(halfLifeYeet);
  75.             }            
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement