error catching

This commit is contained in:
2020-06-17 16:41:54 -05:00
parent ce77a6e048
commit 0e6223e863
2 changed files with 29 additions and 15 deletions

View File

@@ -68,12 +68,18 @@ abstract class Sorter {
* @return returns a SortResult object with the name of the sorting algorithm used, the sorted array of numbers, the number of comparisons used to sort, and the number of writes to arrays used to sort
*/
public SortResult measuredSort(){
Instant start = Instant.now();
this.sort();
Instant end = Instant.now();
Duration time = Duration.between(start,end);
SortResult output = new SortResult(sortType, numbers, comparisonsUsed, writesUsed, time);
return output;
if(numbers.length!=0){
Instant start = Instant.now();
this.sort();
Instant end = Instant.now();
Duration time = Duration.between(start,end);
SortResult output = new SortResult(sortType, numbers, comparisonsUsed, writesUsed, time);
return output;
}
else{
System.out.println("Nothing to sort using "+sortType);
return null;
}
}