Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. public class SortDemo
  2. {
  3.  
  4. public static void main(String[] args) throws IOException
  5. {
  6. //Scans for the file
  7. Scanner sc = new Scanner(new File("names.txt"));
  8.  
  9. List<String> lines = new ArrayList<String>();
  10.  
  11. //Creates an array based on the next lines
  12. while (sc.hasNextLine())
  13. {
  14. lines.add(sc.nextLine());
  15. }
  16.  
  17. //Array created from the file
  18. String[] values = lines.toArray(new String[0]);
  19.  
  20.  
  21. // for(String E:values)
  22. // System.out.println(E);
  23. //Objects used to sort the array
  24. ObjectBubbleSorter bubble = new ObjectBubbleSorter();
  25. ObjectInsertionSorter insert = new ObjectInsertionSorter();
  26. ObjectSelectionSorter selection = new ObjectSelectionSorter();
  27. ObjectQuickSorter quick = new ObjectQuickSorter();
  28.  
  29.  
  30. bubble.bubbleSortReverse(values);
  31. //Calling the methods to sort the array
  32. bubble.bubbleSort(values);
  33. selection.selectionSort(values);
  34. insert.insertionSort(values);
  35. quick.quickSort(values);
  36.  
  37. //Formats the output into a neat table
  38. System.out.println("Sort\t\t" + " Comparisons\t" +
  39. " Modifications");
  40. System.out.println("------------- " + "----------- " +
  41. "-------------");
  42. System.out.println("Bubble");
  43. System.out.println("original data\t\t" + bubble.getComp() +
  44. "\t\t" + bubble.getMod());
  45. System.out.println("Selection");
  46. System.out.println("original data\t\t" + selection.getComp() +
  47. "\t\t" + selection.getMod());
  48. System.out.println("Insertion");
  49. System.out.println("original data\t\t" + insert.getComp() +
  50. "\t\t" + insert.getMod());
  51. System.out.println("Quick");
  52. System.out.println("original data\t\t" + quick.getComp() +
  53. "\t\t" + quick.getMod());
  54.  
  55. //Calling the methods to sort the array
  56. bubble.bubbleSort(values);
  57. selection.selectionSort(values);
  58. insert.insertionSort(values);
  59. quick.quickSort(values);
  60.  
  61. //Formats the output into a neat table
  62. System.out.println("Sort\t\t" + " Comparisons\t" +
  63. " Modifications");
  64. System.out.println("------------- " + "----------- " +
  65. "-------------");
  66. System.out.println("Bubble");
  67. System.out.println("original data\t\t" + bubble.getComp() +
  68. "\t\t" + bubble.getMod());
  69. System.out.println("Selection");
  70. System.out.println("original data\t\t" + selection.getComp() +
  71. "\t\t" + selection.getMod());
  72. System.out.println("Insertion");
  73. System.out.println("original data\t\t" + insert.getComp() +
  74. "\t\t" + insert.getMod());
  75. System.out.println("Quick");
  76. System.out.println("original data\t\t" + quick.getComp() +
  77. "\t\t" + quick.getMod());
  78.  
  79. //Calling the methods to sort the array
  80. bubble.bubbleSort(values);
  81. selection.selectionSort(values);
  82. insert.insertionSort(values);
  83. quick.quickSort(values);
  84.  
  85. //Formats the output into a neat table
  86. System.out.println("Sort\t\t" + " Comparisons\t" +
  87. " Modifications");
  88. System.out.println("------------- " + "----------- " +
  89. "-------------");
  90. System.out.println("Bubble");
  91. System.out.println("original data\t\t" + bubble.getComp() +
  92. "\t\t" + bubble.getMod());
  93. System.out.println("Selection");
  94. System.out.println("original data\t\t" + selection.getComp() +
  95. "\t\t" + selection.getMod());
  96. System.out.println("Insertion");
  97. System.out.println("original data\t\t" + insert.getComp() +
  98. "\t\t" + insert.getMod());
  99. System.out.println("Quick");
  100. System.out.println("original data\t\t" + quick.getComp() +
  101. "\t\t" + quick.getMod());
  102.  
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement