Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,73 @@
|
|||
PROC PrintArray(INT ARRAY a INT size)
|
||||
INT i
|
||||
|
||||
Put('[)
|
||||
FOR i=0 TO size-1
|
||||
DO
|
||||
IF i>0 THEN Put(' ) FI
|
||||
PrintI(a(i))
|
||||
OD
|
||||
Put(']) PutE()
|
||||
RETURN
|
||||
|
||||
PROC Flip(INT ARRAY a INT last)
|
||||
INT i,n,tmp
|
||||
|
||||
n=(last-1)/2
|
||||
FOR i=0 TO n
|
||||
DO
|
||||
tmp=a(i)
|
||||
a(i)=a(last-i)
|
||||
a(last-i)=tmp
|
||||
OD
|
||||
RETURN
|
||||
|
||||
PROC PancakeSort(INT ARRAY a INT size)
|
||||
INT i,j,maxpos
|
||||
|
||||
i=size-1
|
||||
WHILE i>=0
|
||||
DO
|
||||
maxpos=i
|
||||
FOR j=0 TO i-1
|
||||
DO
|
||||
IF a(j)>a(maxpos) THEN
|
||||
maxpos=j
|
||||
FI
|
||||
OD
|
||||
|
||||
IF maxpos#i THEN
|
||||
IF maxpos#0 THEN
|
||||
Flip(a,maxpos)
|
||||
FI
|
||||
Flip(a,i)
|
||||
FI
|
||||
|
||||
i==-1
|
||||
OD
|
||||
RETURN
|
||||
|
||||
PROC Test(INT ARRAY a INT size)
|
||||
PrintE("Array before sort:")
|
||||
PrintArray(a,size)
|
||||
PancakeSort(a,size)
|
||||
PrintE("Array after sort:")
|
||||
PrintArray(a,size)
|
||||
PutE()
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
INT ARRAY
|
||||
a(10)=[1 4 65535 0 3 7 4 8 20 65530],
|
||||
b(21)=[10 9 8 7 6 5 4 3 2 1 0
|
||||
65535 65534 65533 65532 65531
|
||||
65530 65529 65528 65527 65526],
|
||||
c(8)=[101 102 103 104 105 106 107 108],
|
||||
d(12)=[1 65535 1 65535 1 65535 1
|
||||
65535 1 65535 1 65535]
|
||||
|
||||
Test(a,10)
|
||||
Test(b,21)
|
||||
Test(c,8)
|
||||
Test(d,12)
|
||||
RETURN
|
||||
Loading…
Add table
Add a link
Reference in a new issue