Sorting algorithms/Quicksort: Difference between revisions

Content added Content deleted
(→‎{{header|Ruby}}: ++ sather (a sather guru likely can do it better and using methods or technics I dont know still))
m (→‎{{header|Sather}}: |.| instead of toarray(.))
Line 1,289: Line 1,289:
=={{header|Sather}}==
=={{header|Sather}}==
<lang sather>class SORT{T < $IS_LT{T}} is
<lang sather>class SORT{T < $IS_LT{T}} is
private toarray(v:T):ARRAY{T} is
res ::= #ARRAY{T}(1);
res[0] := v;
return res;
end;


private afilter(a:ARRAY{T}, cmp:ROUT{T,T}:BOOL, p:T):ARRAY{T} is
private afilter(a:ARRAY{T}, cmp:ROUT{T,T}:BOOL, p:T):ARRAY{T} is
Line 1,299: Line 1,294:
loop v ::= a.elt!;
loop v ::= a.elt!;
if cmp.call(v, p) then
if cmp.call(v, p) then
filtered := filtered.append(toarray(v));
filtered := filtered.append(|v|);
end;
end;
end;
end;
Line 1,315: Line 1,310:
quick_sort(inout right);
quick_sort(inout right);
res ::= #ARRAY{T};
res ::= #ARRAY{T};
res := res.append(left, toarray(pivot), right);
res := res.append(left, |pivot|, right);
a := res;
a := res;
end;
end;