all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,70 @@
|
|||
itemCount = 20
|
||||
dim A(itemCount)
|
||||
dim tmp(itemCount) 'merge sort needs additionally same amount of storage
|
||||
|
||||
for i = 1 to itemCount
|
||||
A(i) = int(rnd(1) * 100)
|
||||
next i
|
||||
|
||||
print "Before Sort"
|
||||
call printArray itemCount
|
||||
|
||||
call mergeSort 1,itemCount
|
||||
|
||||
print "After Sort"
|
||||
call printArray itemCount
|
||||
end
|
||||
|
||||
'------------------------------------------
|
||||
sub mergeSort start, theEnd
|
||||
if theEnd-start < 1 then exit sub
|
||||
if theEnd-start = 1 then
|
||||
if A(start)>A(theEnd) then
|
||||
tmp=A(start)
|
||||
A(start)=A(theEnd)
|
||||
A(theEnd)=tmp
|
||||
end if
|
||||
exit sub
|
||||
end if
|
||||
middle = int((start+theEnd)/2)
|
||||
call mergeSort start, middle
|
||||
call mergeSort middle+1, theEnd
|
||||
call merge start, middle, theEnd
|
||||
end sub
|
||||
|
||||
sub merge start, middle, theEnd
|
||||
i = start: j = middle+1: k = start
|
||||
while i<=middle OR j<=theEnd
|
||||
select case
|
||||
case i<=middle AND j<=theEnd
|
||||
if A(i)<=A(j) then
|
||||
tmp(k)=A(i)
|
||||
i=i+1
|
||||
else
|
||||
tmp(k)=A(j)
|
||||
j=j+1
|
||||
end if
|
||||
k=k+1
|
||||
case i<=middle
|
||||
tmp(k)=A(i)
|
||||
i=i+1
|
||||
k=k+1
|
||||
case else 'j<=theEnd
|
||||
tmp(k)=A(j)
|
||||
j=j+1
|
||||
k=k+1
|
||||
end select
|
||||
wend
|
||||
|
||||
for i = start to theEnd
|
||||
A(i)=tmp(i)
|
||||
next
|
||||
end sub
|
||||
|
||||
'===========================================
|
||||
sub printArray itemCount
|
||||
for i = 1 to itemCount
|
||||
print using("###", A(i));
|
||||
next i
|
||||
print
|
||||
end sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue