I can't sleep so I tried working on Selection Sort which states:

First find the smallest element in the array and exchange it with the element 
in the first position, then find the second smallest element and exchange it 
with the element in the second position, and continue in this way until the 
entire array is sorted. Its asymptotic complexity is 
O<http://rosettacode.org/wiki/O>(n2) making it inefficient on large arrays.
http://rosettacode.org/wiki/Selection_sort

The best I can do is:
selectionSort=: 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
)


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

   selectionSort data

11 18 46 51 54 56 63 74 76 81

I tried figuring out how to do this without looping but I can't. Can it be done 
without loops?

r/Alex

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to