Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,44 @@
|
|||
Module Bubble {
|
||||
function bubblesort {
|
||||
dim a()
|
||||
\\ [] is a stack object, interpreter pass current stack pointer, and set a new stack for current stack
|
||||
\\ array( stackobject ) get a stack object and return an array
|
||||
a()=array([])
|
||||
itemcount=len(a())
|
||||
repeat {
|
||||
haschange=false
|
||||
if itemcount>1 then {
|
||||
for index=0 to itemcount-2 {
|
||||
if a(index)>a(index+1) then swap a(index), a(index+1) : haschange=true
|
||||
}
|
||||
}
|
||||
itemcount--
|
||||
} until not haschange
|
||||
=a()
|
||||
}
|
||||
\\ function can take parameters
|
||||
Print bubblesort(5,3,2,7,6,1)
|
||||
A=(2, 10, 17, 13, 20, 14, 3, 17, 16, 16)
|
||||
|
||||
\\ !A copy values from array A to function stack
|
||||
B=bubblesort(!A)
|
||||
Print Len(A)=10
|
||||
Print B
|
||||
\\ Print array in descending order
|
||||
k=each(b, -1, 1)
|
||||
While k {
|
||||
Print Array(k),
|
||||
}
|
||||
\\ sort two arrays in one
|
||||
Print BubbleSort(!A, !B)
|
||||
\\ We can use a stack object, and values pop from object
|
||||
Z=Stack:=2, 10, 17, 13, 20, 14, 3, 17, 16, 16
|
||||
Print Len(Z)=10
|
||||
Def GetStack(x)=Stack(x)
|
||||
Z1=GetStack(BubbleSort(!Z))
|
||||
Print Type$(Z1)="mStiva"
|
||||
Print Z1
|
||||
Print Len(Z1)
|
||||
Print Len(Z)=0 ' now Z is empty
|
||||
}
|
||||
Bubble
|
||||
Loading…
Add table
Add a link
Reference in a new issue