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/Algorithms/SortArrays/QuickSortFunctional.pas
2024-03-10 20:32:51 +03:00

15 lines
401 B
ObjectPascal
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Быстрая сортировка Ч. Хоара
// Неэффективный код, иллюстрирующий суть алгоритма
function QS(a: array of integer): array of integer :=
if a.Length < 2 then
a
else
QS(a[1:].FindAll(y->y<=a[0])) + a[:1] + QS(a[1:].FindAll(y->y>a[0]));
begin
var a := ArrRandom(20);
a.Println;
var b := QS(a);
b.Println;
end.