Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
circlesort(v)=
|
||||
{
|
||||
local(v=v); \\ share with cs
|
||||
while (cs(1, #v),);
|
||||
v;
|
||||
}
|
||||
cs(lo, hi)=
|
||||
{
|
||||
if (lo == hi, return (0));
|
||||
my(high=hi,low=lo,mid=(hi-lo)\2,swaps);
|
||||
while (lo < hi,
|
||||
if (v[lo] > v[hi],
|
||||
[v[lo],v[hi]]=[v[hi],v[lo]];
|
||||
swaps++
|
||||
);
|
||||
lo++;
|
||||
hi--
|
||||
);
|
||||
if (lo==hi && v[lo] > v[hi+1],
|
||||
[v[lo],v[hi+1]]=[v[hi+1],v[lo]];
|
||||
swaps++
|
||||
);
|
||||
swaps + cs(low,low+mid) + cs(low+mid+1,high);
|
||||
}
|
||||
print(example=[6,7,8,9,2,5,3,4,1]);
|
||||
print(circlesort(example));
|
||||
Loading…
Add table
Add a link
Reference in a new issue