Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,31 +1,45 @@
|
|||
/*REXX program uses a disjointed sublist to sort a random list of values. */
|
||||
parse arg old ',' idx /*obtain the optional lists from the CL*/
|
||||
if old='' then old= 7 6 5 4 3 2 1 0 /*Not specified: Then use the default.*/
|
||||
if idx='' then idx= 7 2 8 /* " " " " " " */
|
||||
say ' list of indices:' idx; say /* [↑] is for one─based lists. */
|
||||
say ' unsorted list:' old /*display the old list of numbers. */
|
||||
say ' sorted list:' disjoint_sort(old,idx) /*sort 1st list using 2nd list indices.*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
disjoint_sort: procedure; parse arg x,ix; y=; z=; p= 0
|
||||
ix= sortL(ix) /*ensure the index list is sorted*/
|
||||
do i=1 for words(ix) /*extract indexed values from X.*/
|
||||
z= z word(x, word(ix, i) ) /*pick the correct value from X.*/
|
||||
end /*j*/
|
||||
z= sortL(z) /*sort extracted (indexed) values*/
|
||||
do m=1 for words(x) /*re─build (re-populate) X list.*/
|
||||
if wordpos(m, ix)==0 then y=y word(x,m) /*is the same or new?*/
|
||||
else do; p= p + 1; y= y word(z, p)
|
||||
end
|
||||
end /*m*/
|
||||
return strip(y)
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
sortL: procedure; parse arg L; n= words(L); do j=1 for n; @.j= word(L,j)
|
||||
end /*j*/
|
||||
do k=1 for n-1 /*sort a list using a slow method*/
|
||||
do m=k+1 to n; if @.m<@.k then parse value @.k @.m with @.m @.k
|
||||
end /*m*/
|
||||
end /*k*/ /* [↑] use PARSE for swapping.*/
|
||||
$= @.1; do j=2 to n; $= $ @.j
|
||||
end /*j*/
|
||||
return $
|
||||
-- 21 Jan 2026
|
||||
include Setting
|
||||
|
||||
say 'SORT DISJOINT SUBLIST'
|
||||
say version
|
||||
say
|
||||
call Prepare
|
||||
say 'INPUT'
|
||||
call Stemshow 'vals. inds.idx.',3
|
||||
-- Order by index, sync value
|
||||
call Stemsort 'inds.idx.','inds.val.'
|
||||
-- Order by value, don't sync index
|
||||
call Stemsort 'inds.val.'
|
||||
-- Put ordered values back in list
|
||||
call Update
|
||||
say 'OUTPUT'
|
||||
call Stemshow 'vals.',3
|
||||
exit
|
||||
|
||||
Prepare:
|
||||
procedure expose vals. inds.
|
||||
-- Save values
|
||||
values=7 6 5 4 3 2 1 0; n=Words(values)
|
||||
do i=1 to n
|
||||
vals.i=Word(values,i)
|
||||
end
|
||||
vals.0=n
|
||||
-- Save 1-based indices and their values
|
||||
indices=7 2 8; n=Words(indices)
|
||||
do i=1 to n
|
||||
index=Word(indices,i); inds.val.i=vals.index; inds.idx.i=index
|
||||
end
|
||||
inds.0=n
|
||||
return
|
||||
|
||||
Update:
|
||||
procedure expose vals. inds.
|
||||
-- Restore sorted values
|
||||
do i=1 to inds.0
|
||||
index=inds.idx.i; vals.index=inds.val.i
|
||||
end
|
||||
return
|
||||
|
||||
-- Stemshow Stemsort
|
||||
include Math
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue