Anonymous user
Doubly-linked list/Definition: Difference between revisions
→{{header|C sharp|C#}}: Added usage notes about framework class; adjusted style
(→{{header|C sharp|C#}}: Added usage notes about framework class; adjusted style) |
|||
Line 356:
=={{header|C sharp}}==
The .NET framework provides the <code>LinkedListNode<T></code> class, which represents an individual node of a linked list, and the <code>LinkedList<T></code> class, which provides abstractions to read and modify a list as if it were a single object. The <code>LinkedListNode<T>.Next</code> and <code>LinkedListNode<T>.Previous</code> properties is read-only, ensuring that all lists must be created using <code>LinkedList<T></code> and that each list can only be mutated using the methods of its <code>LinkedList<T></code> instance (the appropriate .NET accessibility modifiers are used to hide these implementation details).
using System.Collections.Generic;▼
One node instance is forbidden to be in multiple lists; this is enforced using the <code>LinkedListNode<T>.List</code> property, which is set accordingly when a node is added to a <code>LinkedList<T></code> and set to <code>null</code> when it is removed. This also has the effect of preventing cycles.
Though mutating the ''structure'' of a list can only be done through the <code>LinkedList<T></code> class, mutating the values contained by the nodes of a list is done through its individual <code>LinkedListNode<T></code> instances, as the <code>LinkedListNode<T>.Next</code>.Value property is settable.
▲<lang C sharp>using System.Collections.Generic;
{
▲ class Program
{
▲ static void Main(string[] args)
list.AddFirst(".AddFirst() adds at the head.");
▲ LinkedList<string> list = new LinkedList<string>();
LinkedListNode<string> head
▲ LinkedListNode<string> tail = list.Find(".AddLast() adds at the tail.");
}
}
}</lang>▼
{{out}}
▲</lang>
=={{header|Clojure}}==
|