Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package avlandbs;
- 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 empirically compare the performance of
- * these operations on the trees.
- * @author Maame Nyarko
- * @SEE AVLTree, AVLTreeException, BSTree, BSTreeException,
- * @since 03-09-2018
- */
- public class TwoTreesAnalyzer
- {
- /**
- * @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<String> avlTree = new AVLTree<>();
- BSTree<String> bsTree = new BSTree<>();
- Scanner inFile = new Scanner(new FileReader(args[0]));
- while(inFile.hasNext()){
- String cmd = inFile.next();
- if(cmd.equals("insert"))
- {
- String word = inFile.next();
- avlTree.insert(word.toUpperCase());
- bsTree.insert(word.toUpperCase());
- System.out.println("inserted: "+word.toUpperCase()+" in the AVL");
- }
- else if(cmd.equals("remove"))
- {
- String word = inFile.next();
- avlTree.remove(word);
- bsTree.remove(word);
- }
- else if(cmd.equals("traverse"))
- {
- String word = inFile.next();
- if(word.equals("-order")){
- avlTree.traverse(,System.out.println());
- bsTree.traverse(x,System.out.println(x));
- }
- if(word.equals("-level")){
- avlTree.levelTraverse(System.out.println());
- bsTree.levelTraverse(System.out.println(x));
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment