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
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
$constant NUM_ITEMS = 10
|
||||
|
||||
dim integer items(NUM_ITEMS)
|
||||
var i, j, t = integer
|
||||
|
||||
rem - create a randomly-ordered list of numbers
|
||||
for i = 1 to NUM_ITEMS
|
||||
items(i) = int(rnd(1) * 100) + 1
|
||||
next i
|
||||
|
||||
rem - show unsorted list
|
||||
print "Unsorted list: ";
|
||||
for i = 1 to NUM_ITEMS
|
||||
print items(i);
|
||||
next i
|
||||
print
|
||||
|
||||
rem - sort the list
|
||||
for i = 1 to NUM_ITEMS
|
||||
j = i
|
||||
while j > 1 and items(j-1) > items(j) do
|
||||
begin
|
||||
t = items(j)
|
||||
items(j) = items(j-1)
|
||||
items(j-1) = t
|
||||
j = j - 1
|
||||
end
|
||||
next i
|
||||
|
||||
rem - show the sorted list
|
||||
print "Sorted list : ";
|
||||
for i = 1 to NUM_ITEMS
|
||||
print items(i);
|
||||
next i
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue