Guest User

Untitled

a guest
Mar 19th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. package avlandbs;
  2.  
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.io.PrintStream;
  6. import java.util.Scanner;
  7. import java.util.function.Function;
  8.  
  9.  
  10. /**
  11. * Performs insertions and searches, using the same data set,on a binary search
  12. * tree and an AVL tree to compare the empirically compare the performance of
  13. * these operations on the trees.
  14. * @author Maame Nyarko
  15. * @SEE AVLTree, AVLTreeException, BSTree, BSTreeException,
  16. * @since 03-09-2018
  17. */
  18. public class TwoTreesAnalyzer
  19. {
  20. /**
  21. * @param args the command line arguments
  22. * @throws AVLTreeException
  23. * @throws BSTreeException
  24. * @throws java.io.IOException
  25. */
  26. public static void main(String[] args) throws AVLTreeException, BSTreeException, IOException
  27. {
  28. AVLTree<String> avlTree = new AVLTree<>();
  29. BSTree<String> bsTree = new BSTree<>();
  30.  
  31. Scanner inFile = new Scanner(new FileReader(args[0]));
  32. while(inFile.hasNext()){
  33. String cmd = inFile.next();
  34. if(cmd.equals("insert"))
  35. {
  36. String word = inFile.next();
  37. avlTree.insert(word.toUpperCase());
  38. bsTree.insert(word.toUpperCase());
  39. System.out.println("inserted: "+word.toUpperCase()+" in the AVL");
  40. }
  41. else if(cmd.equals("remove"))
  42. {
  43. String word = inFile.next();
  44. avlTree.remove(word);
  45. bsTree.remove(word);
  46. }
  47. else if(cmd.equals("traverse"))
  48. {
  49. String word = inFile.next();
  50. if(word.equals("-order")){
  51. avlTree.traverse(,System.out.println());
  52. bsTree.traverse(x,System.out.println(x));
  53. }
  54. if(word.equals("-level")){
  55. avlTree.levelTraverse(System.out.println());
  56. bsTree.levelTraverse(System.out.println(x));
  57. }
  58.  
  59.  
  60. }
  61. }
  62. }
Add Comment
Please, Sign In to add comment