Singly-linked list/Element definition: Difference between revisions

Content added Content deleted
(not a good way, maybe I'll try later)
(added Icon/Unicon example)
Line 217: Line 217:


but that would be really awkward to use.
but that would be really awkward to use.

== Icon and Unicon ==

The Icon version works in both Icon and Unicon. Unicon also permits a class-based definition.

=== {{header|Icon}} ===

<lang Icon>
record Node (value, successor)
</lang>

=== {{header|Unicon}} ===

<lang Unicon>
class Node (value, successor)
initially (value, successor)
self.value := value
self.successor := successor
end
</lang>

With either the record or the class definition, new linked lists are easily created and manipulated:

<lang Icon>
procedure main ()
n := Node(1, Node (2))
write (n.value)
write (n.successor.value)
end
</lang>


=={{header|J}}==
=={{header|J}}==