Skip to content

Instantly share code, notes, and snippets.

@HBFLEX
Created October 20, 2023 23:22
Show Gist options
  • Save HBFLEX/865424207428697e845e066ee77184c8 to your computer and use it in GitHub Desktop.
Save HBFLEX/865424207428697e845e066ee77184c8 to your computer and use it in GitHub Desktop.
keen-spray-1020
void main(){
List<int> numbers = [10, 4, 2, 6, 3, 30];
final stopWatch = Stopwatch();
stopWatch.start();
selectionSort(numbers);
stopWatch.stop();
for(int n in numbers) {print(n);}
print('It took ${stopWatch.elapsedMilliseconds} ms time to sort');
}
void selectionSort(List<int> arr){
int length = arr.length;
int lowest = arr[0];
int temp;
for(int i = 0; i < length; i++){
for(int j = i + 1; j < length; j++){
if(arr[i] > arr[j]){
lowest = arr[j];
temp = arr[i];
arr[i] = lowest;
arr[j] = temp;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment