Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Collections;
Namespace generic
{
// Implementation of simple linked list, one-way (generic)
Class generic class
{
Public static void Main ()
{
Shortlist <string> list = new shortlist <string> ();
List. AddLast ("500 ");
List. AddLast ("400 ");
List. AddLast ("300 ");
List. AddLast ("200 ");
// When the generic version of IEnumerable is used, foreach is also of type security. In some cases, it is impossible to write types other than string.
Foreach (string I in list)
{
Console. WriteLine (I );
}
Console. ReadLine ();
}
}
//// The definition of a generic class is similar to that of a general class. If you use a generic type declaration, this type can be used as a field member or a parameter type.
Class initialize listnode <T>
{
// Project value
Private T value;
Private synchronized listnode <T> next;
Private synchronized listnode <T> prev;
Public writable listnode (T value)
{
This. value = value;
}
Public T Value
{
// Read-only attribute
Get
{
Return this. value;
}
}
// Next
Public writable listnode <T> Next
{
Get {return next ;}
Set {next = value ;}
}
// Previous
Public writable listnode <T> Prev
{
Get {return prev ;}
Set {prev = value ;}
}
}
Class Sequence List <T>: IEnumerable <T>
{
// The first
Private synchronized listnode <T> first;
Internal listnode <T> First
{
Get {return first ;}
Set {first = value ;}
}
// Last
Private synchronized listnode <T> last;
Internal listnode <T> Last
{
Get {return last ;}
Set {last = value ;}
}
// Insert from the back
Public writable listnode <T> AddLast (T node)
{
Inclulistnode <T> newNode = new inclulistnode <T> (node );
If (first = null)
{
// The Last reference is always updated.
First = newNode;
Last = first;
}
Else
{
// Point the reference of the next node of the current last node to a new object.
Last. Next = newNode;
// Update the last Node
Last = newNode;
}
Return newNode;
}
Public IEnumerator <T> GetEnumerator ()
{
Repeated listnode <T> current = first;
While (current! = Null)
{
Yield return current. Value;
// The address of the new reference pointing to the next node
Current = current. Next;
&