I wrote for myself quick sort procedure. Like all works normally. Estimate, how much clear the code turned out: type TDoubleWithPointer=record val:double; point:pointer; end; procedure TDoubleWithPointerArray. QSort; var arr1, arr2:array of TDoubleWithPointer; i:integer; procedure DoQSort (intervalbeg, intervallast:integer); var curcount:integer; sumval:double; aveval:double; ii:integer; curvalscount:integer; lowvalscount:integer; begin curcount: = intervallast-intervalbeg+1; if curcount <=1 then exit;//Only one element, it is not necessary to sort//we Find mean value in our interval: sumval: = 0; for ii: = intervalbeg to intervallast do sumval: = sumval+arr1 [ii].val; aveval: = sumval/curcount;//we Place elements, big aveval, in the first part arr2: curvalscount: = 0; for ii: = intervalbeg to intervallast do if arr1 [ii].val> aveval then begin inc (curvalscount); arr2 [intervalbeg+curvalscount-1]: =arr1 [ii]; end; lowvalscount: = curvalscount;//we Place elements, smaller or equal aveval, in the second part arr2: for ii: = intervalbeg to intervallast do if not (arr1 [ii].val> aveval) then begin inc (curvalscount); arr2 [intervalbeg+curvalscount-1]: =arr1 [ii]; end;//It is moved arr2 in arr1: for ii: = intervalbeg to intervallast do arr1 [ii]: =arr2 [ii]; if (lowvalscount=0) or (lowvalscount=curcount) then exit;//All elements are equal in an interval, it is impossible to sort doqsort (intervalbeg, intervalbeg+lowvalscount-1); doqsort (intervalbeg+lowvalscount, intervallast); end; begin setlength (arr1, fcount); setlength (arr2, fcount); for i: = 0 to fcount-1 do arr1 [i]: =GetValue (i); doqsort (0, fcount-1); for i: = 0 to fcount-1 do SetValue (i, arr1 [i]); setlength (arr1,0); setlength (arr2,0); end;