Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,38 @@
|
|||
proc Show(A, N); \Show items in array A with size N
|
||||
int A, N, I;
|
||||
[for I:= 0 to N-1 do
|
||||
[IntOut(0, A(I)); ChOut(0, ^ )];
|
||||
CrLf(0);
|
||||
];
|
||||
|
||||
proc Sort(A, N); \Pancake sort array A with size N
|
||||
int A, N, I, J, JMax;
|
||||
|
||||
proc Flip(K); \Reverse order of array items from 0 to K
|
||||
int K, L, T;
|
||||
[L:= 0;
|
||||
while L < K do
|
||||
[T:= A(L); A(L):= A(K); A(K):= T; \swap
|
||||
K:= K-1;
|
||||
L:= L+1;
|
||||
];
|
||||
Show(A, N); \show result of reversed items
|
||||
];
|
||||
|
||||
[for I:= N-1 downto 1 do
|
||||
[JMax:= 0;
|
||||
for J:= 1 to I do
|
||||
if A(J) > A(JMax) then JMax:= J;
|
||||
if JMax < I then
|
||||
[Flip(JMax);
|
||||
Flip(I);
|
||||
];
|
||||
];
|
||||
];
|
||||
|
||||
int A, N;
|
||||
[A:= [6, 7, 2, 1, 8, 9, 5, 3, 4];
|
||||
N:= 9;
|
||||
Show(A, N); \show initial
|
||||
Sort(A, N);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue