Eliminated swap counting, got bubble, selection, and insertion sort working
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user