using StgSharp.Graphics; using StgSharp.Logic; using System; using System.Collections; using System.Collections.Generic; using System.Text; namespace StgSharp { public class LinkedList:INode>,IEnumerable where T: INode { internal readonly ContainerNode _heading; private ContainerNode _cache; private bool isEmpty; public LinkedList() { _heading = new ContainerNode(null); isEmpty = true; #if DEBUG Console.WriteLine("Linked list init ok"); #endif } public T First { get { return _heading._next._value; } private set { _heading._next = value.ID; } } public T Tail { get { return _heading._previous._value; } private set { _heading._previous = value.ID; } } /// /// Add an item to the tail of linked list. /// /// The item ready to add to the list public void Add(T t) { //checkout if the linkedlist is null if (isEmpty) { _heading._next = t.ID; _heading._previous = t.ID; t.Next = _heading; t.Previous = _heading; isEmpty = false; Console.WriteLine("1st item ok"); Console.WriteLine(_heading._next); Console.WriteLine(_heading._previous); } else { Console.WriteLine("next begin"); t.Next = _heading; Console.WriteLine("step 01 ok"); t.Previous = _heading.Previous; Console.WriteLine("step 02 ok"); _heading._previous._next = t.ID; Console.WriteLine("step 03 ok"); _heading._previous = t.ID; } } public void Remove(T node) { foreach (INode item in this) { if (item == node) { node.SelfDestrcut(); break; } } } public void RemoveTail() { //check out if the list has only one member if (Tail == First) { First = default; isEmpty = true; } else { Tail.Previous.Next = _heading; Tail.Next = null; } } IEnumerator IEnumerable.GetEnumerator() { return new LinkedListEnumrator(this); } } }