pascalabcnet/_Presentations/2015 New Features/Programs/_QS5.pas

20 lines
426 B
ObjectPascal
Raw Permalink Normal View History

2015-05-14 22:35:07 +03:00
function QuickSort(a: sequence of integer): sequence of integer;
begin
if a.Count = 0 then
Result := a
else
begin
var f := a.First();
var sm := QuickSort(a.Skip(1).Where(x->x<=f));
var la := QuickSort(a.Skip(1).Where(x->x>f));
Result := sm + f + la
end;
end;
begin
var a := ArrRandom(1000);
writeln(MillisecondsDelta);
var b := QuickSort(a);
//b.Println;
writeln(MillisecondsDelta);
end.