Singly-linked list/Element definition: Difference between revisions

Content deleted Content added
Rdm (talk | contribs)
Line 157:
 
Due to Forth's lack of typechecking, 'b' in the above examples does not have to be an actual cell, but can instead be the head pointer of the list.
 
If you assume the links always point to each other, you can abbreviate the code to:
 
<lang forth>\ insert `new` after `this`
: insert-after ( new this -- )
2dup @ swap ( this.next new ) ! ( new this ) ! ;</lang>
 
And to remove data from a list:
 
<lang forth>\ remove and return the item after `this`.
: remove-next ( this -- next )
dup @ ( this next )
dup @ ( this next next.next )
rot ( next next.next this ) ! ;</lang>
 
=={{header|Fortran}}==