Shop OBEX P1 Docs P2 Docs Learn Events
order array in decimal ascending order — Parallax Forums

order array in decimal ascending order

Bobb FwedBobb Fwed Posts: 1,119
edited 2009-02-11 22:36 in Propeller 1
I have an array (5 longs in length) and I would like to arrange the values of the array in ascending order. Is there an easy way to do that? I would assume that some recursive function could do this, does someone already have something like this written?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-11 19:31
    For a small array like this, a simple exchange sort will work nicely. If ArraySize is the size of the array, do
    for i from 0 to ArraySize-2
       for j from i+1 to ArraySize-1
          if array[noparse][[/noparse] i ] > array[noparse][[/noparse] j ]
             temp := array[noparse][[/noparse] i ]
             array[noparse][[/noparse] i ] := array[noparse][[/noparse] j ]
             array[noparse][[/noparse] j ] := temp
    
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2009-02-11 19:42
    thanks I'll try it out
  • SRLMSRLM Posts: 5,045
    edited 2009-02-11 22:05
    There are lots of sorting algorithms available for large amounts of data. For arrays smaller than about 20, insertion sort works fine. The larger you get though, the worse off it is. Something like quick sort would work well if you have lots of data.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2009-02-11 22:36
    Ya. I am only using it for 5 elements at the moment....in the future, at worst, 10.
Sign In or Register to comment.