Singly-linked list/Element definition: Difference between revisions

Content deleted Content added
→‎[[C plus plus|C++]]: Point to C++ instead of C plus plus
m Changed over to headers.
Line 3: 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.
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.


==[[Ada]]==
=={{header|Ada}}==
[[Category:Ada]]


type Link;
type Link;
Line 13: Line 12:
end record;
end record;


==[[C]]==
=={{header|C}}==


struct link {
struct link {
Line 54: Line 53:
Note that the generic version works for any type, not only integral types.
Note that the generic version works for any type, not only integral types.


==[[Clean]]==
=={{header|Clean}}==
[[Category:Clean]]
import StdMaybe
import StdMaybe
:: Link t = { next :: Maybe (Link t), data :: t }
:: 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.
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: Line 69:
end;
end;


==[[E]]==
=={{header|E}}==
[[Category:E]]


interface LinkedList guards LinkedListStamp {}
interface LinkedList guards LinkedListStamp {}
Line 90: Line 85:
}
}


==[[Forth]]==
=={{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.
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: Line 122:
but that would be really awkward to use.
but that would be really awkward to use.


==[[Perl]]==
=={{header|Perl}}==
[[Category:Perl]]
Just use an array. You can traverse and splice it any way. Linked lists are way too low level.
Just use an array. You can traverse and splice it any way. Linked lists are way too low level.


Line 139: Line 132:
$node{next} = \%bar_node; # mutable
$node{next} = \%bar_node; # mutable


==[[Pop11]]==
=={{header|Pop11}}==
[[Category:Pop11]]


List are built in into Pop11, so normally on would just use them:
List are built in into Pop11, so normally on would just use them:
Line 180: Line 172:
l1 =>
l1 =>


==[[Python]]==
=={{header|Python}}==
[[Category:Python]]


The Node class implements also iteration for more Pythonic iteration over linked lists.
The Node class implements also iteration for more Pythonic iteration over linked lists.
Line 197: Line 188:
</pre>
</pre>


==[[Ruby]]==
=={{header|Ruby}}==
[[Category:Ruby]]


class ListNode
class ListNode