Sorting algorithms/Selection sort: Difference between revisions
Content added Content deleted
(C++ Selection Sort) |
(Added support for J language) |
||
Line 390: | Line 390: | ||
selectR small output (x:xs) | x < small = selectR x (small:output) xs |
selectR small output (x:xs) | x < small = selectR x (small:output) xs |
||
| otherwise = selectR small (x:output) xs</lang> |
| otherwise = selectR small (x:output) xs</lang> |
||
=={{header|J}}== |
|||
Create the following script and load it to a J session. |
|||
<lang j>shellSort=: verb define |
|||
data=. y |
|||
for_xyz. y do. |
|||
temp=. xyz_index }. data |
|||
nvidx=. xyz_index + temp i. <./ temp |
|||
data=. ((xyz_index, nvidx) { data) (nvidx, xyz_index) } data |
|||
end. |
|||
data |
|||
)</lang> |
|||
To validate: |
|||
<lang j>NB. We generate 10 random numbers between 0 and 99 and assign to a variable |
|||
[data=. 10 ? 100 |
|||
51 18 81 46 11 54 74 63 56 76 |
|||
shellSort data |
|||
11 18 46 51 54 56 63 74 76 81 |
|||
</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |