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

13 lines
300 B
ObjectPascal
Raw Permalink Normal View History

2015-09-06 18:46:31 +03:00
function QuickSort(a: sequence of integer): sequence of integer;
begin
Result := a.Count = 0 ? a :
QuickSort(a.Skip(1).Where(x -> x <= a.First))
+ a.First +
QuickSort(a.Skip(1).Where(x -> x > a.First));
2015-09-06 18:46:31 +03:00
end;
2015-05-14 22:35:07 +03:00
begin
2015-09-06 18:46:31 +03:00
var a := ArrRandom(20);
a.Println;
2015-09-06 18:46:31 +03:00
QuickSort(a).Println;
2015-05-14 22:35:07 +03:00
end.