all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,38 @@
|
|||
#! A simple Bubble Sort function
|
||||
value| array count changed |
|
||||
[ ( address count -- )
|
||||
to count to array
|
||||
count 0
|
||||
[ count 0
|
||||
[ i array array.get i 1 + array array.get 2dup >
|
||||
[ i array array.put i 1 + array array.put ]
|
||||
[ 2drop ] ifTrueFalse
|
||||
] countedLoop
|
||||
count 1 - to count
|
||||
] countedLoop
|
||||
] is bsort
|
||||
|
||||
#! Code to display an array
|
||||
[ ( array count -- )
|
||||
0 swap [ dup i swap array.get . ] countedLoop drop cr
|
||||
] is .array
|
||||
|
||||
#! Create a 10-cell array
|
||||
10 cells is-array foo
|
||||
|
||||
#! Fill it with random values
|
||||
20 1 foo array.put
|
||||
50 2 foo array.put
|
||||
650 3 foo array.put
|
||||
120 4 foo array.put
|
||||
110 5 foo array.put
|
||||
101 6 foo array.put
|
||||
1321 7 foo array.put
|
||||
1310 8 foo array.put
|
||||
987 9 foo array.put
|
||||
10 10 foo array.put
|
||||
|
||||
#! Display the array, sort it, and display it again
|
||||
foo 10 .array
|
||||
foo 10 bsort
|
||||
foo 10 .array
|
||||
Loading…
Add table
Add a link
Reference in a new issue