Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SortDemo
- {
- public static void main(String[] args) throws IOException
- {
- //Scans for the file
- Scanner sc = new Scanner(new File("names.txt"));
- List<String> lines = new ArrayList<String>();
- //Creates an array based on the next lines
- while (sc.hasNextLine())
- {
- lines.add(sc.nextLine());
- }
- //Array created from the file
- String[] values = lines.toArray(new String[0]);
- // for(String E:values)
- // System.out.println(E);
- //Objects used to sort the array
- ObjectBubbleSorter bubble = new ObjectBubbleSorter();
- ObjectInsertionSorter insert = new ObjectInsertionSorter();
- ObjectSelectionSorter selection = new ObjectSelectionSorter();
- ObjectQuickSorter quick = new ObjectQuickSorter();
- bubble.bubbleSortReverse(values);
- //Calling the methods to sort the array
- bubble.bubbleSort(values);
- selection.selectionSort(values);
- insert.insertionSort(values);
- quick.quickSort(values);
- //Formats the output into a neat table
- System.out.println("Sort\t\t" + " Comparisons\t" +
- " Modifications");
- System.out.println("------------- " + "----------- " +
- "-------------");
- System.out.println("Bubble");
- System.out.println("original data\t\t" + bubble.getComp() +
- "\t\t" + bubble.getMod());
- System.out.println("Selection");
- System.out.println("original data\t\t" + selection.getComp() +
- "\t\t" + selection.getMod());
- System.out.println("Insertion");
- System.out.println("original data\t\t" + insert.getComp() +
- "\t\t" + insert.getMod());
- System.out.println("Quick");
- System.out.println("original data\t\t" + quick.getComp() +
- "\t\t" + quick.getMod());
- //Calling the methods to sort the array
- bubble.bubbleSort(values);
- selection.selectionSort(values);
- insert.insertionSort(values);
- quick.quickSort(values);
- //Formats the output into a neat table
- System.out.println("Sort\t\t" + " Comparisons\t" +
- " Modifications");
- System.out.println("------------- " + "----------- " +
- "-------------");
- System.out.println("Bubble");
- System.out.println("original data\t\t" + bubble.getComp() +
- "\t\t" + bubble.getMod());
- System.out.println("Selection");
- System.out.println("original data\t\t" + selection.getComp() +
- "\t\t" + selection.getMod());
- System.out.println("Insertion");
- System.out.println("original data\t\t" + insert.getComp() +
- "\t\t" + insert.getMod());
- System.out.println("Quick");
- System.out.println("original data\t\t" + quick.getComp() +
- "\t\t" + quick.getMod());
- //Calling the methods to sort the array
- bubble.bubbleSort(values);
- selection.selectionSort(values);
- insert.insertionSort(values);
- quick.quickSort(values);
- //Formats the output into a neat table
- System.out.println("Sort\t\t" + " Comparisons\t" +
- " Modifications");
- System.out.println("------------- " + "----------- " +
- "-------------");
- System.out.println("Bubble");
- System.out.println("original data\t\t" + bubble.getComp() +
- "\t\t" + bubble.getMod());
- System.out.println("Selection");
- System.out.println("original data\t\t" + selection.getComp() +
- "\t\t" + selection.getMod());
- System.out.println("Insertion");
- System.out.println("original data\t\t" + insert.getComp() +
- "\t\t" + insert.getMod());
- System.out.println("Quick");
- System.out.println("original data\t\t" + quick.getComp() +
- "\t\t" + quick.getMod());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement