Board index » delphi » Efficient sorting algorithm?

Efficient sorting algorithm?

Hello pascal programmers,

Does anyone have an efficient sorting algorithm to share
that sorts and copy to another array, or sorts and rank,
and then copy to another array?  

Most of the examples I find in pascal books sort arrays
"in place", in other words, the array is modified by permuting
its components into (ascending) order.

Thanks for any pointers,

Daniel Mailly
University of British Columbia
Vancouver, BC Canada
email: mai...@unixg.ubc.ca

 

Re:Efficient sorting algorithm?


In article <mailly-2504962246110...@port23.annex1.net.ubc.ca>

Quote
Daniel Mailly wrote:
>Hello pascal programmers,

>Does anyone have an efficient sorting algorithm to share
>that sorts and copy to another array, or sorts and rank,
>and then copy to another array?  

>Most of the examples I find in pascal books sort arrays
>"in place", in other words, the array is modified by permuting
>its components into (ascending) order.

If you're looking for a practical solution rather than Pascal code
I can offer you a pair of *.COM files that do a reasonably good
job.  I use them in real mode programs and sort internal only for
protected mode versions.  The program swaps to EMS, calls the sort
utility and a few seconds later I'm reading 8500 or so ordered
records.

Let me know if you're interested.

The other solution would be to copy everything to the second array
and sort it there.  Same results, but the order of the original
list is preserved.

                      ...red

Knowledge is one of the few things that you
can give away and still keep for yourself.

Re:Efficient sorting algorithm?


Hi mailly and everybody else!

m> Does anyone have an efficient sorting algorithm to share
m> that sorts and copy to another array, or sorts and rank,
m> and then copy to another array?
m>
m> Most of the examples I find in pascal books sort arrays
m> "in place", in other words, the array is modified by permuting
m> its components into (ascending) order.

So first copy your array to another one, than sort one of them.
Move(array1,array2,(sizeof(array1)) should do it on the fly.

cu,        Clemens

* * * * * * * * * * *  on the net since tuesday  * * * * * * * * * * * * *
_P.S._ Answer and/or comment _please_ (also) as follow-up-to: poster

Re:Efficient sorting algorithm?


Quote
Daniel Mailly (mai...@unixg.ubc.ca) wrote:

: Does anyone have an efficient sorting algorithm to share
: that sorts and copy to another array, or sorts and rank,
: and then copy to another array?  
:

If your are dealing with a small amount of data (in other words, the speed
of the sort shouldn't matter too much), the easiest way would be to copy
the data in order to the new array.

  FOR i := 1 TO MaxElement DO
    Insert(Array2, Array1[i]);

Otherwise, I would copy the entire array and then sort it.

  BlockMove(Array2, Array1, SizeOf(Array1));
    (** I'm not sure I have the syntax here quite right **)
  FastSort(Array2);

Good luck ---

Other Threads