Singly-linked list/Element definition: Difference between revisions

m
Changed over to headers.
(→‎[[C plus plus|C++]]: Point to C++ instead of C plus plus)
m (Changed over to headers.)
Line 3:
Define the data structure for a [[singly-linked list]] element. Said element should contain a data member capable of holding a numeric value, and the link to the next element should be mutable.
 
==[[{{header|Ada]]}}==
[[Category:Ada]]
 
type Link;
Line 13 ⟶ 12:
end record;
 
==[[{{header|C]]}}==
 
struct link {
Line 54 ⟶ 53:
Note that the generic version works for any type, not only integral types.
 
==[[{{header|Clean]]}}==
[[Category:Clean]]
import StdMaybe
:: Link t = { next :: Maybe (Link t), data :: t }
 
=={{header|Delphi}}==
==[[Delphi]] / [[Object Pascal]] / [[Turbo Pascal]] / Standard [[Pascal]]==
[[Category:Delphi]]
[[Category:Pascal]]
 
A simple one way list. I use a generic pointer for the data that way it can point to any structure, individual variable or whatever. Note that in Standard Pascal, there are no generic pointers, therefore one has to settle for a specific data type there.
Line 73 ⟶ 69:
end;
 
==[[{{header|E]]}}==
[[Category:E]]
 
interface LinkedList guards LinkedListStamp {}
Line 90 ⟶ 85:
}
 
==[[{{header|Forth]]}}==
[[Category:Forth]]
 
Forth has no "struct" facility, but you can easily implement a single linked list with a data cell using a double-cell value.
Line 128 ⟶ 122:
but that would be really awkward to use.
 
==[[{{header|Perl]]}}==
[[Category:Perl]]
Just use an array. You can traverse and splice it any way. Linked lists are way too low level.
 
Line 139 ⟶ 132:
$node{next} = \%bar_node; # mutable
 
==[[{{header|Pop11]]}}==
[[Category:Pop11]]
 
List are built in into Pop11, so normally on would just use them:
Line 180 ⟶ 172:
l1 =>
 
==[[{{header|Python]]}}==
[[Category:Python]]
 
The Node class implements also iteration for more Pythonic iteration over linked lists.
Line 197 ⟶ 188:
</pre>
 
==[[{{header|Ruby]]}}==
[[Category:Ruby]]
 
class ListNode
Anonymous user