Doubly-linked list/Definition: Difference between revisions

Line 600:
 
=={{header|D}}==
<lang d>classimport LinkedList(T)std.stdio;
 
class LinkedList(T)
{
Node!(T) head, tail;
 
/** Iterate in the forward direction. */
int opApply (int delegate(uint, Node!(T)) dg)
Line 619 ⟶ 621:
return result;
}
 
static LinkedList!(T) fromArray (T[] array)
{
Line 641 ⟶ 643:
LinkedList!(T) parent;
T value;
 
this (Node!(T) next, Node!(T) previous, T value, LinkedList!(T) parent)
in
Line 657 ⟶ 659:
this.value = value;
this.parent = parent;
 
if (parent.head == next)
parent.head = this;
Line 663 ⟶ 665:
parent.tail = this;
}
 
/** Insert an element after this one. */
void insertAfter (T value)
{
new Node!(T)(thisnext, nextthis, value, parent);
}
 
/** Insert an element before this one. */
void insertBefore (T value)
{
new Node!(T)(previousthis, thisprevious, value, parent);
}
 
/** Remove the current node from the list. */
void remove ()
Line 692 ⟶ 694:
void main ()
{
char[]string[] sample = ["was", "it", "a", "cat", "I", "saw"];
auto list = LinkedList!(char[])string.fromArray (sample);
for (auto elem = list.head; elem; elem = elem.next)
{
Anonymous user