Anonymous user
Algebraic data types: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments.
(C# changed output to look more like a tree) |
m (→{{header|REXX}}: added/changed whitespace and comments.) |
||
Line 1,803:
The nodes used for this example are taken from the Wikipedia example at:
[[https://en.wikipedia.org/wiki/Red%E2%80%93black_tree#/media/File:Red-black_tree_example.svg red black tree, an example]]
<lang rexx>/*REXX pgm builds a red/black tree (with verification & validation),
parse arg nodes '/' insert /*obtain optional arguments from the CL*/
if nodes='' then nodes = 13.8.17 8.1.11 17.15.25 1.6 25.22.27
if insert='' then insert= 22.44 44.66
call Dnodes nodes /*define nodes, balance them as added. */
call Dnodes insert /*insert
call Lnodes /*list the nodes (with
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
parse var t p '.' a "." b '.' x 1 . . . xx▼
call Vnodes p a b▼
if x\=='' then call err "too many nodes specified: " xx▼
if p\==top then if @.p==. then call err "node isn't defined: " p▼
if p ==top then do; !.p=1; L.1=p; end /*assign the top node. */▼
@.p=a b; n=!.p + 1 /*assign node; bump level.*/▼
if a\=='' then do; !.a=n; @.a=; maxL=max(maxL, !.a); end▼
if b\=='' then do; !.b=n; @.b=; maxL=max(maxL, !.b); end▼
▲ L.n=space(L.n a b) /*append to the level list*/
end /*j*/▼
return▼
/*──────────────────────────────────────────────────────────────────────────────────────*/
L.n= space(L.n a b) /*append to the level list*/
▲ return
/*──────────────────────────────────────────────────────────────────────────────────────*/
Lnodes:
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
Vnodes: arg $v;
return</lang>
{{out|output|text= when using the default inputs:}}
|