This repository has been archived on 2024-12-25. You can view files and clone it, but cannot push or open issues or pull requests.
OldPascalProjects/Samples/LINQ/QuickSortLinq.pas
2023-06-20 21:52:24 +03:00

19 lines
387 B
ObjectPascal

function QuickSort(a: sequence of integer): sequence of integer;
begin
if a.Count = 0 then
Result := a
else
begin
var head := a.First();
var tail := a.Skip(1);
Result := QuickSort(tail.Where(x->x<=head)) +
head +
QuickSort(tail.Where(x->x>head));
end;
end;
begin
var a := ArrRandom(20);
a.Println;
QuickSort(a).Println;
end.