Sorting algorithms/Selection sort: Difference between revisions
Content deleted Content added
Added solution for Action! |
Adding the code for Dart, translated from Java |
||
Line 1,145: | Line 1,145: | ||
{{out}} |
{{out}} |
||
<pre>[1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7, 8, 9, 9, 9]</pre> |
<pre>[1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7, 8, 9, 9, 9]</pre> |
||
=={{header|Dart}}== |
|||
{{trans | Java}} |
|||
<lang dart> |
|||
void main() { |
|||
List<int> a = selectionSort([1100, 2, 56, 200, -52, 3, 99, 33, 177, -199]); |
|||
print('$a'); |
|||
} |
|||
selectionSort(List<int> array){ |
|||
for(int currentPlace = 0;currentPlace<array.length-1;currentPlace++){ |
|||
int smallest = 4294967296; //maxInt |
|||
int smallestAt = currentPlace+1; |
|||
for(int check = currentPlace; check<array.length;check++){ |
|||
if(array[check]<smallest){ |
|||
smallestAt = check; |
|||
smallest = array[check]; |
|||
} |
|||
} |
|||
int temp = array[currentPlace]; |
|||
array[currentPlace] = array[smallestAt]; |
|||
array[smallestAt] = temp; |
|||
} |
|||
return array; |
|||
} |
|||
</lang> |
|||
{{out}} |
|||
<pre> unsorted array: [1100, 2, 56, 200, -52, 3, 99, 33, 177, -199] |
|||
a sorted: [-199, -52, 2, 3, 33, 56, 99, 177, 200, 1100] </pre> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |