aboutsummaryrefslogtreecommitdiff
path: root/comparison/Inpla/src/qsort-800000-reuse.in
blob: 810e446ae14b9735df5f62f503e7c41300a323e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Quick sort
QS(ret) >< [] => ret~(*R)[];
QS(ret) >< (int x):xs =>
	(*R)Part(x, left, right)~xs,
	(*L)QS(cntl)~left, QS(cntr)~right,
	Append(ret, x:cntl)~cntr;

// Note: `Append' is implemented as built-in.


Part(int x, a, b) >< [] => a~(*L)[], b~(*R)[];
Part(int x, a, b) >< (int y):ys
| y<x => b~(*R)(y:cnt), (*L)Part(x, a, cnt)~ys
| _   => a~(*R)(y:cnt), (*L)Part(x, cnt, b)~ys;


const LIST_ELEM=800000;

MkRandList(ret) >< (int n)
| n>0 => ret~(rd:cnt), (*L)MkRandList(cnt)~(n-1) 
  where rd=rand(10000)
| _ => ret~[];

MkRandList(cnt)~(LIST_ELEM),
QS(ret)~cnt;
ret;