Singly-linked list/Element definition: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: syntax coloured) |
|||
Line 1,244: | Line 1,244: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
In Phix, types are used for validation and debugging rather than specification purposes. For extensive run-time checking you could use something like |
In Phix, types are used for validation and debugging rather than specification purposes. For extensive run-time checking you could use something like |
||
<lang Phix> |
<!--<lang Phix>(phixonline)--> |
||
<span style="color: #008080;">enum</span> <span style="color: #000000;">NEXT</span><span style="color: #0000FF;">,</span><span style="color: #000000;">DATA</span> |
|||
type slnode(object x) |
|||
<span style="color: #008080;">type</span> <span style="color: #000000;">slnode</span><span style="color: #0000FF;">(</span><span style="color: #004080;">object</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">)</span> |
|||
return (sequence(x) and length(x)=DATA and myotherudt(x[DATA]) and integer(x[NEXT]) |
|||
<span style="color: #008080;">return</span> <span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">DATA</span> <span style="color: #008080;">and</span> <span style="color: #000000;">myotherudt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">[</span><span style="color: #000000;">DATA</span><span style="color: #0000FF;">])</span> <span style="color: #008080;">and</span> <span style="color: #004080;">integer</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">[</span><span style="color: #000000;">NEXT</span><span style="color: #0000FF;">])</span> |
|||
end type</lang> |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">type</span> |
|||
<!--</lang>--> |
|||
But more often you would just use the builtin sequences. It is worth noting that while "node lists", such as |
But more often you would just use the builtin sequences. It is worth noting that while "node lists", such as |
||
{{2},{'A',3},{'B',4},{'C',0}} are one way to hold a linked list (with the first element a dummy header), |
{{2},{'A',3},{'B',4},{'C',0}} are one way to hold a linked list (with the first element a dummy header), |