Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -0,0 +1,56 @@
Main:
call Generate
call Show
call Heapsort
call Show
exit
Generate:
call Random,,12345
n = 10
do i = 1 to n
stem.i = Random()
end
stem.0 = n
return
Show:
do i = 1 to n
say right(i,2) right(stem.i,3)
end
say
return
HeapSort:
procedure expose stem.
n = stem.0
if n < 2 then
return
n = stem.0; l = (n%2)+1; s = n
do while 1
if l > 1 then do
l = l-1; r = stem.l
end
else do
r = stem.s; stem.s = stem.1; s = s-1
if s = 1 then do
stem.1 = r
leave
end
end
i = l; j = l*2
do while j <= s
if j < s then do
k = j+1
if stem.j < stem.k then
j = j+1
end
if r < stem.j then do
stem.i = stem.j; i = j; j = j+i
end
else
j = s+1
end
stem.i = r
end
return

View file

@ -1,11 +1,11 @@
fn main() {
mut test_arr := [4, 65, 2, -31, 0, 99, 2, 83, 782, 1]
println('Before : $test_arr')
println("Before : $test_arr")
heap_sort(mut test_arr) // Heap Sort
println('After : $test_arr')
println("After : $test_arr")
}
[direct_array_access]
@[direct_array_access]
fn heap_sort(mut array []int) {
n := array.len
for i := n/2; i > -1; i-- {
@ -17,7 +17,7 @@ fn heap_sort(mut array []int) {
}
}
[direct_array_access]
@[direct_array_access]
fn heapify(mut array []int, n int, i int) {
mut largest := i
left := 2 * i + 1