Eliminated swap counting, got bubble, selection, and insertion sort working
This commit is contained in:
@@ -84,7 +84,7 @@ public class AlgorithmTester{
|
||||
boolean quick=false, counting=false; //radix=false, merge=false;
|
||||
boolean ready=false;
|
||||
System.out.print("Please enter file name: ");
|
||||
filename = sc.nextLine();
|
||||
filename = sc.next();
|
||||
while(!ready){
|
||||
try{
|
||||
System.out.println("Enter the number of the algorithms you wish to use.");
|
||||
@@ -119,36 +119,40 @@ public class AlgorithmTester{
|
||||
case 0 -> ready=true;
|
||||
default -> System.out.println("Invalid input");
|
||||
}
|
||||
} catch(InputMismatchException ex){
|
||||
}catch(InputMismatchException ex){
|
||||
System.out.println("Invalid input");
|
||||
}
|
||||
ArrayList<SortResult> results = new ArrayList<SortResult>();
|
||||
if(bubble){
|
||||
var bubSorter = new BubbleSorter(filename);
|
||||
results.add(bubSorter.measuredSort());
|
||||
}
|
||||
if(selection){
|
||||
var selSorter = new SelectionSorter(filename);
|
||||
results.add(selSorter.measuredSort());
|
||||
}
|
||||
if(insertion){
|
||||
var inSorter = new InsertionSorter(filename);
|
||||
results.add(inSorter.measuredSort());
|
||||
}
|
||||
if(counting){
|
||||
var countSorter = new CountingSorter(filename);
|
||||
results.add(countSorter.measuredSort());
|
||||
}
|
||||
if(quick){
|
||||
var qSorter = new QuickSorter(filename);
|
||||
results.add(qSorter.measuredSort());
|
||||
}
|
||||
for(SortResult e: results){
|
||||
System.out.println(e.getSortType()+" sort took:");
|
||||
System.out.println(e.getComparisonsUsed()+" comparisons");
|
||||
System.out.println(e.getSwapsUsed()+" swaps");
|
||||
System.out.println(e.getTimeUsed().toMillis()+" milliseconds\n");
|
||||
}
|
||||
}
|
||||
ArrayList<SortResult> results = new ArrayList<SortResult>();
|
||||
if(bubble){
|
||||
BubbleSorter bubSorter = new BubbleSorter(filename);
|
||||
results.add(bubSorter.measuredSort());
|
||||
}
|
||||
if(selection){
|
||||
SelectionSorter selSorter = new SelectionSorter(filename);
|
||||
results.add(selSorter.measuredSort());
|
||||
}
|
||||
if(insertion){
|
||||
InsertionSorter inSorter = new InsertionSorter(filename);
|
||||
results.add(inSorter.measuredSort());
|
||||
}
|
||||
if(counting){
|
||||
CountingSorter countSorter = new CountingSorter(filename);
|
||||
results.add(countSorter.measuredSort());
|
||||
}
|
||||
if(quick){
|
||||
QuickSorter qSorter = new QuickSorter(filename);
|
||||
results.add(qSorter.measuredSort());
|
||||
}
|
||||
for(SortResult e: results){
|
||||
//for(int i: e.getSortedArray()){
|
||||
// System.out.print(i+" ");
|
||||
//}
|
||||
System.out.println("");
|
||||
System.out.println(e.getSortType()+" sort took:");
|
||||
System.out.println(e.getComparisonsUsed()+" comparisons");
|
||||
System.out.println(e.getTimeUsed().toMillis()+" milliseconds\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user