SRL Archive - SRL Archives

QuickSortEx (QS for extended values)


marpis

2009-08-25 09:41:47

Self explanatory

E: I didn't write this myself, if someone missed that :rolleyes:


procedure QuickSortEx(var A: array of Extended; iLo, iHi: Integer);
var
Lo, Hi: Integer;
Pivot, T: Extended;
begin
Lo := iLo;
Hi := iHi;
Pivot := A[(Lo + Hi) div 2];
repeat
while A[Lo] < Pivot do Inc(Lo) ;
while A[Hi] > Pivot do Dec(Hi) ;
if Lo <= Hi then
begin
T := A[Lo];
A[Lo] := A[Hi];
A[Hi] := T;
Inc(Lo) ;
Dec(Hi) ;
end;
until Lo > Hi;
if Hi > iLo then QuickSortEx(A, iLo, Hi) ;
if Lo < iHi then QuickSortEx(A, Lo, iHi) ;
end;


A := [2.2, 1.2, 4.3, 6.4, 2.1];
QuickSortEx(A, Low(A), High(A));

marpis

2009-10-17 08:59:18

Bump?
Very useful for all colorfunctions that deal with HSL or XYZ

EvilChicken!

2009-10-17 09:18:57

Talk to Freddy about adding that into SCAR.

ape

2009-10-17 11:28:10

Excellent, Scar already has quick sort built in but this could be useful for other things where it would not be possible to use the built in method.

marpis

2009-10-17 15:20:54

From: EvilChicken!
Talk to Freddy about adding that into SCAR.


Why not SRL? What's the difference ^^ We already have stuff that is not strictly for RS n' stuf..

senrath

2009-10-17 15:21:58

From: marpis
Why not SRL? What's the difference ^^ We already have stuff that is not strictly for RS n' stuf..


Because if it's added directly into SCAR it'll go faster.

Quickmarch

2009-10-17 15:57:13

Just put it in a plugin.

n3ss3s

2009-10-17 17:25:16

From: ape
Excellent, Scar already has quick sort built in but this could be useful for other things where it would not be possible to use the built in method.


Stating the obvious…

ape

2009-10-17 18:39:05

From: n3ss3s
Stating the obvious…

Must not be that obvious as people are discussing adding it into SCAR.

senrath

2009-10-17 18:41:54

From: ape
Must not be that obvious as people are discussing adding it into SCAR.


Yeah, we are. Because this is not the same as the one that's in SCAR. The one that's in SCAR can only handle a TIntegerArray. This one works with an Array of Extended.