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,24 @@
Elegant:
procedure expose stem.
push 1 stem.0
do while queued() > 0
pull l r
if l < r then do
m = (l+r)%2; p = stem.m; i = l-1; j = r+1
do forever
do until stem.j <= p
j = j-1
end
do until stem.i >= p
i = i+1
end
if i < j then do
t = stem.i; stem.i = stem.j; stem.j = t
end
else
leave
end
push l j; push j+1 r
end
end
return

View file

@ -0,0 +1,20 @@
Recursive:
procedure expose stem.
arg l r
m = (l+r)%2; p = stem.m
i = l; j = r
do while i <= j
do i = i while stem.i < p
end
do j = j by -1 while stem.j > p
end
if i <= j then do
t = stem.i; stem.i = stem.j; stem.j = t
i = i+1; j = j-1
end
end
if l < j then
call Recursive l j
if i < r then
call Recursive i r
return

View file

@ -0,0 +1,56 @@
Optimized:
procedure expose stem.
n = stem.0; s = 1; sl.1 = 1; sr.1 = n
do until s = 0
l = sl.s; r = sr.s; s = s-1
do until l >= r
if r-l < 11 then do
do i = l+1 to r
a = stem.i
do j=i-1 by -1 to l while stem.j > a
k = j+1; stem.k = stem.j
end
k = j+1; stem.k = a
end
if s = 0 then
leave
l = sl.s; r = sr.s; s = s-1
end
else do
m = (l+r)%2
if stem.l > stem.m then do
t = stem.l; stem.l = stem.m; stem.m = t
end
if stem.l > stem.r then do
t = stem.l; stem.l = stem.r; stem.r = t
end
if stem.m > stem.r then do
t = stem.m; stem.m = stem.r; stem.r = t
end
i = l; j = r; p = stem.m
do until i > j
do i = i while stem.i < p
end
do j = j by -1 while stem.j > p
end
if i <= j then do
t = stem.i; stem.i = stem.j; stem.j = t
i = i+1; j = j-1
end
end
if j-l < r-i then do
if i < r then do
s = s+1; sl.s = i; sr.s = r
end
r = j
end
else do
if l < j then do
s = s+1; sl.s = l; sr.s = j
end
l = i
end
end
end
end
return

View file

@ -0,0 +1,73 @@
numeric digits 9
parse version version; say version Digits() 'digits'
arg n v
if n = '' then n = 10
if v = '' then v = 1
show = (n > 0); n = Abs(n)
say 'Quicksort: Timing Version' v 'for' n 'random numbers'
call Generate
if show then call ShowSave
select
when v = 1 then do
call Save2Stem
call Time 'r'; call Qsort n; say 'Qsort' format(time('e'),3,3) 'seconds'
if show then call ShowStem
end
when v = 2 then do
call Time 'r'; call Save2Stack; say 'Save2Stack' format(time('e'),3,3) 'seconds'
call Time 'r'; call Quicksort; say 'Quicksort ' format(time('e'),3,3) 'seconds'
call Time 'r'; call Stack2Stem; say 'Stack2Stem' format(time('e'),3,3) 'seconds'
if show then call ShowStem
end
when v = 3 then do
call Save2Stem
call Time 'r'; call Elegant; say 'Elegant' format(time('e'),3,3) 'seconds'
if show then call ShowStem
end
when v = 4 then do
call Save2Stem
call Time 'r'; call Recursive 1 n; say 'Recursive' format(time('e'),3,3) 'seconds'
if show then call ShowStem
end
when v = 5 then do
call Save2Stem
call Time 'r'; call Optimized; say 'Optimized' format(time('e'),3,3) 'seconds'
if show then call ShowStem
end
otherwise nop
end
say
exit
Generate:
do x = 1 to n
save.x = 10000*Random(0,9999)+Random(0,9999)
end
save.0 = n
return
ShowSave:
do x = 1 to 5
say x save.x
end
do x = n-4 to n
say x save.x
end
return
ShowStem:
do x = 1 to 5
say x stem.x
end
do x = n-4 to n
say x stem.x
end
return
Save2Stem:
do x = 0 to n
stem.x = save.x
end
return
/* Sorting procedures follow, not shown here */