Sorting algorithms/Selection sort: Difference between revisions

no edit summary
m (Using lang tags now.)
No edit summary
Line 137:
200
</pre>
 
=={{header|D}}==
<lang d>
// Written in D 2.0.
 
import std.stdio;
 
void swap(T)(ref T lhs, ref T rhs) {
T temp = lhs;
lhs = rhs;
rhs = temp;
}
 
void selectionSort(T)(T[] data) {
foreach(i; 0..data.length) {
size_t minIndex = i;
foreach(j; i + 1..data.length) {
if(data[j] < data[minIndex]) {
minIndex = j;
}
}
swap(data[i], data[minIndex]);
}
}
 
void main() {
auto foo = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2];
selectionSort(foo);
writeln(foo);
}
</lang>
 
=={{header|Forth}}==
Anonymous user