Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,80 @@
|
|||
DEFINE MAX_COUNT="100"
|
||||
INT ARRAY stack(MAX_COUNT)
|
||||
INT stackSize
|
||||
|
||||
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 InitStack()
|
||||
stackSize=0
|
||||
RETURN
|
||||
|
||||
BYTE FUNC IsEmpty()
|
||||
IF stackSize=0 THEN
|
||||
RETURN (1)
|
||||
FI
|
||||
RETURN (0)
|
||||
|
||||
PROC Push(INT low,high)
|
||||
stack(stackSize)=low stackSize==+1
|
||||
stack(stackSize)=high stackSize==+1
|
||||
RETURN
|
||||
|
||||
PROC Pop(INT POINTER low,high)
|
||||
stackSize==-1 high^=stack(stackSize)
|
||||
stackSize==-1 low^=stack(stackSize)
|
||||
RETURN
|
||||
|
||||
PROC StoogeSort(INT ARRAY a INT size)
|
||||
INT l,h,t,tmp
|
||||
|
||||
InitStack()
|
||||
Push(0,size-1)
|
||||
WHILE IsEmpty()=0
|
||||
DO
|
||||
Pop(@l,@h)
|
||||
IF a(l)>a(h) THEN
|
||||
tmp=a(l) a(l)=a(h) a(h)=tmp
|
||||
FI
|
||||
IF h-l>1 THEN
|
||||
t=(h-l+1)/3
|
||||
Push(l,h-t)
|
||||
Push(l+t,h)
|
||||
Push(l,h-t)
|
||||
FI
|
||||
OD
|
||||
RETURN
|
||||
|
||||
PROC Test(INT ARRAY a INT size)
|
||||
PrintE("Array before sort:")
|
||||
PrintArray(a,size)
|
||||
StoogeSort(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