28 lines
841 B
Plaintext
28 lines
841 B
Plaintext
include c:\cxpl\codes; \intrinsic 'code' declarations
|
|
|
|
proc SSort(A, N); \Shell sort array in ascending order
|
|
int A; \address of array
|
|
int N; \number of elements in array (size)
|
|
int I, J, Gap, JG, T;
|
|
[Gap:= N>>1;
|
|
while Gap > 0 do
|
|
[for I:= Gap to N-1 do
|
|
[J:= I - Gap;
|
|
loop [JG:= J + Gap;
|
|
if A(J) <= A(JG) then quit;
|
|
T:= A(J); A(J):= A(JG); A(JG):= T; \swap elements
|
|
J:= J - Gap;
|
|
if J < 0 then quit;
|
|
];
|
|
];
|
|
Gap:= Gap>>1;
|
|
];
|
|
]; \SSort
|
|
|
|
int A, I;
|
|
[A:= [3, 1, 4, 1, 5, 9, 2, 6, 5, 4];
|
|
SSort(A, 10);
|
|
for I:= 0 to 10-1 do [IntOut(0, A(I)); ChOut(0, ^ )];
|
|
CrLf(0);
|
|
]
|