added string array and boolean array for algorithm choices, to make adding new ones easier
This commit is contained in:
@@ -80,46 +80,38 @@ public class AlgorithmTester{
|
||||
private static void sortFile(){
|
||||
String filename;
|
||||
int input;
|
||||
boolean bubble=false, selection=false, insertion=false;
|
||||
boolean quick=false, counting=false; //radix=false, merge=false;
|
||||
// boolean bubble=false, selection=false, insertion=false;
|
||||
//boolean quick=false, counting=false, radix=false, merge=false;
|
||||
boolean ready=false;
|
||||
boolean print=false;
|
||||
String[] sortingAlgoNames = {"bubble","selection","insertion","counting","quick"};
|
||||
boolean[] sortingAlgoChoices = new boolean[sortingAlgoNames.length];
|
||||
System.out.print("\nPlease enter file name: ");
|
||||
filename = sc.next();
|
||||
while(!ready){
|
||||
try{
|
||||
System.out.println("\nEnter the number of an algorithm you wish to use.");
|
||||
System.out.println("Enter the number again to deselect an algorithm.");
|
||||
if(bubble){
|
||||
System.out.print("*");
|
||||
for(int i=0;i<sortingAlgoNames.length;i++){
|
||||
int num=i+1;
|
||||
System.out.print(num+") "+sortingAlgoNames[i]);
|
||||
if(sortingAlgoChoices[i]){
|
||||
System.out.print(" *\n");
|
||||
}
|
||||
else{
|
||||
System.out.print("\n");
|
||||
}
|
||||
}
|
||||
System.out.println("1) bubble sort");
|
||||
if(selection){
|
||||
System.out.print("*");
|
||||
}
|
||||
System.out.println("2) selection sort");
|
||||
if(insertion){
|
||||
System.out.print("*");
|
||||
}
|
||||
System.out.println("3) insertion sort");
|
||||
if(counting){
|
||||
System.out.print("*");
|
||||
}
|
||||
System.out.println("4) counting sort");
|
||||
if(quick){
|
||||
System.out.print("*");
|
||||
}
|
||||
System.out.println("5) quick sort");
|
||||
System.out.println("Enter 0 to continue when all desired algorithms have been selected.");
|
||||
input = sc.nextInt();
|
||||
switch(input){
|
||||
case 1 -> bubble=!bubble;
|
||||
case 2 -> selection=!selection;
|
||||
case 3 -> insertion=!insertion;
|
||||
case 4 -> counting=!counting;
|
||||
case 5 -> quick=!quick;
|
||||
case 0 -> ready=true;
|
||||
default -> System.out.println("Invalid input");
|
||||
if(input>0&&input<=sortingAlgoChoices.length){
|
||||
sortingAlgoChoices[input-1]=!sortingAlgoChoices[input-1];
|
||||
}
|
||||
else if(input==0){
|
||||
ready=true;
|
||||
}
|
||||
else{
|
||||
System.out.println("Invalid input");
|
||||
}
|
||||
}catch(InputMismatchException ex){
|
||||
System.out.println("Invalid input");
|
||||
@@ -138,7 +130,13 @@ public class AlgorithmTester{
|
||||
}catch(InputMismatchException ex){
|
||||
System.out.println("Invalid input, defaulting to no");
|
||||
}
|
||||
boolean bubble=sortingAlgoChoices[0];
|
||||
boolean selection=sortingAlgoChoices[1];
|
||||
boolean insertion=sortingAlgoChoices[2];
|
||||
boolean counting=sortingAlgoChoices[3];
|
||||
boolean quick=sortingAlgoChoices[4];
|
||||
ArrayList<SortResult> results = new ArrayList<SortResult>();
|
||||
|
||||
if(bubble){
|
||||
BubbleSorter bubSorter = new BubbleSorter(filename);
|
||||
results.add(bubSorter.measuredSort());
|
||||
|
||||
Reference in New Issue
Block a user