Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package forestanalyzer;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.util.Scanner;
- import java.util.function.Function;
- /**
- * Performs insertions and searches, using the same data set,on a binary search
- * tree and an AVL tree to compare the performance of
- * these operations on the trees.
- * @author Duncan, Noah Gothreaux
- * @SEE AVLTree, AVLTreeException, BSTree, BSTreeException,
- * @since DATE LAST MODIFIED
- */
- public class ForestAnalyzer
- {
- /**
- * @param args the command line arguments
- * @throws AVLTreeException
- * @throws BSTreeException
- * @throws java.io.IOException
- */
- public static void main(String[] args) throws AVLTreeException, BSTreeException, IOException
- {
- AVLTree yeetAVL=new AVLTree();
- BSTree yeetBS=new BSTree();
- Scanner yeetScan = new Scanner(new FileReader(args[0]));
- Function<String, PrintStream> halfLifeYeet = x ->
- {
- System.out.printf("%-20s%n",x);
- return null;
- };
- String command;
- String yeetTemp;
- while(yeetScan.hasNext())
- {
- if(command.equalsIgnoreCase("insert"))
- {
- yeetTemp = yeetScan.next()
- yeetAVL.insert(yeetTemp);
- yeetBS.insert(yeetTemp);
- System.out.printf("inserted: %s in the AVL%n"
- + "inserted: %s in the BST%n"
- + "Type: size height diameter full? perfect?%n"
- + "AVL: %d %d %d %b %b%n"
- + "BST: %d %d %d %b %b%n"
- ,tempYeet,tempYeet,yeetAVL.size(),yeetAVL.height(),yeetAVL.diameter(),
- yeetAVL.isFull(),yeetAVL.isPerfect(),yeetBS.size(),yeetBS.height(),
- yeetBS.diameter(),yeetBS.isFull(),yeetBS.isPerfect());
- }
- if(command.equalsIgnoreCase("remove"))
- {
- yeetTemp = yeetScan.next()
- yeetAVL.remove(yeetTemp);
- yeetBS.remove(yeetTemp);
- System.out.printf("removed: %s in the AVL%n"
- + "removed: %s in the BST%n"
- + "Type: size height diameter full? perfect?%n"
- + "AVL: %d %d %d %b %b%n"
- + "BST: %d %d %d %b %b%n"
- ,tempYeet,tempYeet,yeetAVL.size(),yeetAVL.height(),yeetAVL.diameter(),
- yeetAVL.isFull(),yeetAVL.isPerfect(),yeetBS.size(),yeetBS.height(),
- yeetBS.diameter(),yeetBS.isFull(),yeetBS.isPerfect());
- }
- if(command.equalsIgnoreCase("traverse"))
- {
- yeetAVL.traverse(halfLifeYeet);
- yeetBS.traverse(halfLifeYeet);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement