Shop OBEX P1 Docs P2 Docs Learn Events
Arrange numbers in ascending order — Parallax Forums

Arrange numbers in ascending order

Zap-oZap-o Posts: 452
edited 2011-05-16 13:50 in Propeller 1
I am having some difficulties even getting started on this issue.

I want to take any 9 numbers and arrange the numbers in ascending order. The problem is that the 9 numbers could be anything (not floating point numbers) and I am not sure how to even start a programming loop to accomplish this.

For example say I have a set of numbers:

1,5,5,3,2,4,1,9,5

After some logic I would like to to have:

1,1,2,3,4,5,5,5,9

I just need a push in the right direction. I looked up medians in the forums but this did not help much since I am running the propeller.

Comments

  • RaymanRayman Posts: 14,877
    edited 2011-05-16 09:38
    That is a very fundamental CS problem and there are many ways to do it...

    "bubble sort" is one way...
  • LeonLeon Posts: 7,620
    edited 2011-05-16 09:41
    The Shell sort is more efficient, and doesn't take any more code.
  • Zap-oZap-o Posts: 452
    edited 2011-05-16 09:41
    Rayman

    Thanks a million. Wiki shows this very clearly and now I can see the light at the end of the tunnel. I will begin programming this.
    Again thanks :)


    * Edited

    Leon thanks as well, ill look further into that too.
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2011-05-16 12:58
    While it was in the Stamp forum, you might find this linked thread helpful, about keeping a running median.
  • max72max72 Posts: 1,155
    edited 2011-05-16 13:50
    check the obex and the propeller forum for past discussions.
    There is an important sorting object, and a related thread considering the advantages and disadvantages of all of them..

    edit: http://obex.parallax.com/objects/715/
    This one looks promising..
Sign In or Register to comment.