Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
|
|
@ -0,0 +1,62 @@
|
|||
//
|
||||
// Insertion Sort in FutureBasic
|
||||
//
|
||||
|
||||
_maxDim = 99 // size of array
|
||||
|
||||
dim theArray(_maxDim) as Int
|
||||
dim x as Int
|
||||
|
||||
// sorts array "theArray"
|
||||
// in ascending order
|
||||
|
||||
void local function insertionSort(arr(_maxDim) as Int, siz as Int)
|
||||
dim as Int j,k,s
|
||||
|
||||
for x = 0 to siz
|
||||
j = x - 1
|
||||
s = 1
|
||||
k = arr(x)
|
||||
while (j => 0) && (s == 1)
|
||||
arr(j + 1) = arr(j)
|
||||
s = 0
|
||||
if arr(j) > k
|
||||
arr(j + 1) = arr(j)
|
||||
j--
|
||||
s = 1
|
||||
end if
|
||||
wend
|
||||
arr(j + 1) = k
|
||||
next x
|
||||
|
||||
end fn
|
||||
//
|
||||
|
||||
//
|
||||
// main
|
||||
//
|
||||
window 1,@"Insertion Sort"
|
||||
|
||||
// load array with random 0-99
|
||||
|
||||
for x = 0 to 99
|
||||
theArray(x) = rnd(100)-1
|
||||
next x
|
||||
|
||||
print "Unsorted:"
|
||||
for x = 1 to 100
|
||||
print theArray(x-1);
|
||||
if x MOD 20 then print "-"; else print
|
||||
next x
|
||||
|
||||
print
|
||||
|
||||
fn insertionSort(@theArray(0),99)
|
||||
|
||||
print "Sorted:"
|
||||
for x = 1 to 100
|
||||
print theArray(x-1);
|
||||
if x MOD 20 then print "-"; else print
|
||||
next x
|
||||
|
||||
handleevents
|
||||
Loading…
Add table
Add a link
Reference in a new issue