Sorting algorithms/Selection sort: Difference between revisions

Content deleted Content added
No edit summary
Line 1,065:
sort -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7</pre>
 
=={{header|Gambas}}==
<lang gambas>
siLow As Short = -99 'Set the lowest value number to create
siHigh As Short = 99 'Set the highest value number to create
siQty As Short = 20 'Set the quantity of numbers to create
 
Public Sub Main()
Dim siToSort As Short[] = CreateNumbersToSort()
Dim siPos, siLow, siChar, siCount As Short
 
PrintOut("To sort: ", siToSort)
 
For siCount = 0 To siToSort.Max
siChar = siCount
For siPos = siCount + 1 To siToSort.Max
If siToSort[siChar] > siToSort[siPos] Then siChar = siPos
Next
siLow = siToSort[siChar]
siToSort.Delete(siChar, 1)
siToSort.Add(siLow, siCount)
Next
 
PrintOut(" Sorted: ", siToSort)
 
End
'---------------------------------------------------------
Public Sub PrintOut(sText As String, siToSort As String[])
Dim siCount As Short
 
Print sText;
 
For siCount = 0 To siToSort.Max
Print siToSort[siCount];
If siCount <> siToSort.max Then Print ", ";
Next
 
Print
 
End
'---------------------------------------------------------
Public Sub CreateNumbersToSort() As Short[]
Dim siCount As Short
Dim siList As New Short[]
 
For siCount = 0 To siQty
siList.Add(Rand(siLow, siHigh))
Next
 
Return siList
 
End</lang>
 
Output:
<pre>
To sort: -11, -64, -20, -84, 94, -60, -82, -82, 37, -30, -75, 73, 19, -97, 81, -26, 55, 8, -15, -31, 36
Sorted: -97, -84, -82, -82, -75, -64, -60, -31, -30, -26, -20, -15, -11, 8, 19, 36, 37, 55, 73, 81, 94
</pre>
=={{header|GAP}}==
<lang gap>SelectionSort := function(v)