Re: LZ: sorting


[Prev][Next][Index][Thread]

Re: LZ: sorting



On Thu, 15 Aug 1996, D Melton wrote:


> Does anyone know a short routine to sort a list?  The list is one byte per
> element, one right after the other in memory.  The routine does not
> necessarily have to be that fast, just short.  Thanks for any help.
 
The bubble sort algorithm is short and easy to code.  It's not real
fast but in assembly with a short list it seems instantaneous
anyway.


You make a pass through the list of n elements and every time you
find that element(n) > element(n+1), you swap them and set a flag
to indicate that you made a swap on that pass.


Keep doing this over and over till you make a pass with no swaps
and your list is sorted.


They call this a bubble sort because the lighter elements "float"
to the surface.


Barry


References: