Created with <3 with dartpad.dev.
Created
October 20, 2023 23:22
-
-
Save HBFLEX/865424207428697e845e066ee77184c8 to your computer and use it in GitHub Desktop.
keen-spray-1020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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