Sorting algorithms/Selection sort: Difference between revisions
Content added Content deleted
(added Ursala) |
|||
Line 421: | Line 421: | ||
=={{header|Ursala}}== |
=={{header|Ursala}}== |
||
The selection_sort function is parameterized by a relational predicate p. |
The selection_sort function is parameterized by a relational predicate p. |
||
In this example, the relational predicate on natural number is used. |
|||
There are no arrays in Ursala so it uses a list, and the selected item |
There are no arrays in Ursala so it uses a list, and the selected item |
||
is deleted from the list |
is deleted from the list and inserted into another on each iteration |
||
rather than swapped with a preceding item of the same list. |
|||
<lang Ursala> |
<lang Ursala> |
||
#import std |
#import std |
||
⚫ | |||
⚫ | |||
⚫ | |||
</lang> |
|||
This is already a bad way to code a sorting algorithm in this |
|||
language, but with only a bit more work, we can get a bigger and |
|||
slower version that more closely simulates the operations of |
|||
repeatedly reordering an array. |
|||
<lang Ursala> |
|||
selection_sort "p" = ~&itB^?a\~&a ^|JahPfatPRC/~& ~=-~BrhPltPClhPrtPCTlrTQrS^D/"p"$- ~& |
|||
</lang> |
|||
Here is a test program sorting by the partial order relation on natural |
|||
numbers. |
|||
<lang Ursala> |
|||
⚫ | |||
#cast %nL |
#cast %nL |
||