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 @@
|
|||
code Reserve=3, ChOut=8, IntOut=11;
|
||||
|
||||
proc MergeSort(A, Low, High); \Sort array A from Low to High
|
||||
int A, Low, High;
|
||||
int B, Mid, H, I, J, K;
|
||||
[if Low >= High then return;
|
||||
Mid:= (Low+High) >> 1; \split array in half (roughly)
|
||||
MergeSort(A, Low, Mid); \sort left half
|
||||
MergeSort(A, Mid+1, High); \sort right half
|
||||
\Merge the two halves in to sorted order
|
||||
B:= Reserve((High-Low+1)*4); \reserve space for working array (4 bytes/int)
|
||||
H:= Low; I:= Low; J:= Mid+1;
|
||||
while H<=Mid & J<=High do \merge while both halves have items
|
||||
if A(H) <= A(J) then [B(I):= A(H); I:= I+1; H:= H+1]
|
||||
else [B(I):= A(J); I:= I+1; J:= J+1];
|
||||
if H > Mid then \copy any remaining elements
|
||||
for K:= J to High do [B(I):= A(K); I:= I+1]
|
||||
else for K:= H to Mid do [B(I):= A(K); I:= I+1];
|
||||
for K:= Low to High do A(K):= B(K);
|
||||
];
|
||||
|
||||
int A, I;
|
||||
[A:= [3, 1, 4, 1, -5, 9, 2, 6, 5, 4];
|
||||
MergeSort(A, 0, 10-1);
|
||||
for I:= 0 to 10-1 do [IntOut(0, A(I)); ChOut(0, ^ )];
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue