VList: Difference between revisions

653 bytes added ,  6 years ago
m
→‎{{header|REXX}}: changed comments and whitespace, moved documentation to its own window, used a template for output.
(Added Kotlin)
m (→‎{{header|REXX}}: changed comments and whitespace, moved documentation to its own window, used a template for output.)
Line 836:
This classic REXX version uses (mostly) the same "input" and operations as the ooRexx version,
except that the (stack) queue isn't changed or used.
 
<lang rexx>/*REXX pgm demonstrates VList operations: add/update/delete/insert/show.*/
/* ╔════════════════════════════════════════════════════════════════════╗
║ ║
║ ┌────────────┬───────────────────────────┐ ║
Line 883:
║ to the end of the VList. Any non-zero decimal fraction may be ║
║ used. I.E.: 63.01 63.5 63.63 63.9 ║
╚════════════════════════════════════════════════════════════════════╝*/
<lang rexx>/*REXX pgmprogram demonstrates VList operations: add/, update/, delete/, insert/, show. */
/*could use: q = 1 2 3 4 */
call q 0, 1 2 3 4 /*populatecould theuse listinstead: with 1──►4 q = 1 2 3 4 */
saycall q(4) 0, 1 2 3 4 /*showpopulate the list indexedwith accessvalues to1 an── item.►4*/
say q(4) /*could use: /*show the q = 1 2 3 4indexed access to an item. */
 
call q 2, 'Fred' /*update (or add) the 2ndsecond item. */
say q(2) q(4) /*show 2ndsecond and 4thfourth items in list.*/
/*0thzeroth item is inserted in the front. */
call q 0, 'Mike' /*insert item in front of the list. */
say q(1) q(2) q(4) /*show 1stfirst, 2ndsecond, and 4thfourth items. */
/*any negative number is deleted. */
call q -1 /*delete the first item in the list. */
say q(1) q(2) q(4) /*show the 1st, 2nd, and 4th items. */
/*Fractional #number inserts an item. */
call q 3.5, '3½' /*insert the item after the 3rdthird item.*/
say q , /*show all the VList items. */
/*Put on a dog and pony show. */
say 'number of items in Vlist:' q() /*show and tell time for the Vlist. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────Q subroutine────────────────────────*/
q: parse arg n 1 na 1 ni,!; w=words(q); $= /*getobtain arguments; args,# items.*/
if symbol('Q')=='LIT' then q= /*var Q may not be defined. */
if arg()==0 then return words(q) /*return the VList item count*/
if arg(1, 'O') then return q /*return the whole shebang. */
if arg()==1 & n>0 then return word(q,n) /*1 positive arg? Return it.*/
if n==0 then do; q=! q; return q; end /*insert in front of the list*/
if n> w then do; q=q !; return q; end /*add it to end. " " " */
na=abs(n) /*we might need use of ABS. */
if \datatype(ni, 'W') & ni>0 then ni=trunc(na) /*Is this an insert. >? TRUNC.*/
else ni=0 /*plain Jane... No? Then a plain Jane.*/
do j=1 for w /* [↓] rebuild the Vlist. */
if j==na then do; if na==n then $=$ !; end /*replace the item in list. */
else $=$ word(q, j) /*an easy-peasy bld(re-)build. */
if j==ni then $=$ ! /*handle the "insert". */
end /*j*/
q=space($); return q return q /*purify,elide returnsuperfluous blanks. */</lang>
{{out|output|text=&nbsp; when using the default input:}}
{{out}}
<pre>
4