piclist 2002\09\06\092227a >
Thread: Sorting numbers
face BY : M. Adam Davis email (remove spam text)

It is possible that no one wants to spend the time making a routine that
might not work for you, or trying to extricate their routine from their

What kind of numbers are you sorting?  Do you just have six registers
and you want to move the values around so they go from lowest to
highest?  Are they signed (negative and positive) or unsigned(positive

And most importantly, what have you tried so far?

If you haven't tried anything (and are hoping for a quick simple piece
of code) then you'll get few responses.

There are several algorithms for sorting.  One particularily simple
algorithm follows:
0. Clear a flag that indicates that the algorithm is still sorting
1. Compare locations (1) and (2).
2. If (1) is greater than (2) then swap the two values and set the flag
3. Compare locations (2) and (3).
4. If (2) is greater than (3) then swap the two values and set the flag
perform the same for 3 and 4, 4 and 5, 5 and 6.
7. If the flag is set, goto 0.

This algorithm is fairly simple and striaghtforward.  If you are unsure
of its operation then perform the work on paper and it should become clear.

There are numerous code examples for comparing two registers and
swapping the values in two registers on http://piclist.com , so you
ought to be able to get this going fairly quickly.  It is not the most
efficient sorter, bu I'll leave that research up to you.



{Quote hidden}

http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

<3D78ABA8.6060809@ubasics.com> 7BIT

See also: www.piclist.com/techref/microchip/devices.htm?key=pic
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Sorting numbers

month overview.

new search...