Eliminated swap counting, got bubble, selection, and insertion sort working

This commit is contained in:
2020-05-31 09:49:28 -05:00
parent c680ec7671
commit 4574231dcb
15 changed files with 1111303 additions and 75 deletions

View File

@@ -12,12 +12,12 @@ abstract class Sorter {
protected String sortType;
protected Integer[] numbers;
protected long swapsUsed = 0;
protected long comparisonsUsed = 0;
public Sorter(String st, String filename){
sortType=st;
RandomNumberFileReader reader = new RandomNumberFileReader(filename);
numbers = new Integer[reader.getNumbers().size()];
reader.getNumbers().toArray(numbers);
}
@@ -29,10 +29,9 @@ abstract class Sorter {
abstract void sort();
void swap(int a, int b){
swapsUsed++;
int tmp = a;
a = b;
b = tmp;
int tmp = numbers[a];
numbers[a] = numbers[b];
numbers[b] = tmp;
}
int compare(int a, int b){
@@ -45,7 +44,7 @@ abstract class Sorter {
this.sort();
Instant end = Instant.now();
Duration time = Duration.between(start,end);
SortResult output = new SortResult(sortType, numbers, comparisonsUsed, swapsUsed, time);
SortResult output = new SortResult(sortType, numbers, comparisonsUsed, time);
return output;
}