Talk:Array sort
From Free Pascal wiki
Jump to navigationJump to search
Error in the algorithm
I think the non-generic used algorithm has an error. I wrote about it: https://forum.lazarus.freepascal.org/index.php/topic,34955.15.html
If you agree, I think it should be changed.
11/11/2021 update I saw no feedback, but the error I still see valid and the fix working, so I changed the Page source code. A full version is now available with more descriptive names on GitHub: https://github.com/zsoltszakaly/quicksortforpascal
Avoid memory-transfer operations
I think it would be better to use user-supplied swap function instead of relying on low-level memory-transfer operations, e.g.:
interface
type
FComp = function ( var data; i, j: integer ): integer;
FSwap = procedure( var data; i, j: integer );
TSort = record
Comp: FComp;
Swap: FSwap;
end;
procedure Sort( var sort: TSort; var data; left, right: integer );
Antonius (talk) 15:16, 18 February 2018 (CET)
- I would think that the memory-transfer method for swapping doesn't play well with managed types (e.g. AnsiString).
I didn't see this page before and wrote a similar ArraySort() procedure which requires a compare function and an exchange functions as arguments.
See: [here]. It comes with predefined compare functions and exchange procedures for all integer and float types and currency as well as for Ansi- and UnicodeString. For arrays of unmanegd types one can omit the exchange procedure.Bart (talk) 17:39, 23 February 2025 (CET)
- I would think that the memory-transfer method for swapping doesn't play well with managed types (e.g. AnsiString).