all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,35 @@
|
|||
pancake_sort: procedure options (main); /* 23 April 2009 */
|
||||
declare a(10) fixed, (i, n, loc) fixed binary;
|
||||
|
||||
a(1) = 3; a(2) = 9; a(3) = 2; a(4) = 7; a(5) = 10;
|
||||
a(6) = 1; a(7) = 8; a(8) = 5; a(9) = 4; a(10) = 6;
|
||||
|
||||
n = hbound(A,1);
|
||||
put skip edit (A) (f(5));
|
||||
do i = 1 to n-1;
|
||||
loc = max(A, n);
|
||||
call flip (A, loc);
|
||||
call flip (A, n);
|
||||
n = n - 1;
|
||||
put skip edit (A) (f(5));
|
||||
end;
|
||||
|
||||
max: procedure (A, k) returns (fixed binary);
|
||||
declare A(*) fixed, k fixed binary;
|
||||
declare (i, maximum, loc) fixed binary;
|
||||
maximum = A(1); loc = 1;
|
||||
do i = 2 to k;
|
||||
if A(i) > maximum then do; maximum = A(i); loc = i; end;
|
||||
end;
|
||||
return (loc);
|
||||
end max;
|
||||
|
||||
flip: procedure (A, k);
|
||||
declare A(*) fixed, k fixed binary;
|
||||
declare (i, t) fixed binary;
|
||||
do i = 1 to (k+1)/2;
|
||||
t = A(i); A(i) = A(k-i+1); A(k-i+1) = t;
|
||||
end;
|
||||
end flip;
|
||||
|
||||
end pancake_sort;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
3 9 2 7 10 1 8 5 4 6
|
||||
6 4 5 8 1 3 9 2 7 10
|
||||
7 2 6 4 5 8 1 3 9 10
|
||||
3 1 7 2 6 4 5 8 9 10
|
||||
5 4 6 2 3 1 7 8 9 10
|
||||
1 3 2 5 4 6 7 8 9 10
|
||||
4 1 3 2 5 6 7 8 9 10
|
||||
2 3 1 4 5 6 7 8 9 10
|
||||
1 2 3 4 5 6 7 8 9 10
|
||||
1 2 3 4 5 6 7 8 9 10
|
||||
Loading…
Add table
Add a link
Reference in a new issue