Exemplo n.º 1
0
        ///<summary>Insert element at the begining of the list</summary>
        ///<param name="value">Value to insert</param>
        public override void Prepend(T value)
        {
            size++;

            DLListNode <T> newNode = new DLListNode <T>(value, beforeHeadNode, beforeHeadNode.Next);

            beforeHeadNode.SetNext(newNode);
            beforeHeadNode.Next.SetPrevious(newNode);
        }
Exemplo n.º 2
0
        ///<summary>Insert element at the end of the list</summary>
        ///<param name="value">Value to append</param>
        public override void Append(T value)
        {
            size++;

            DLListNode <T> after   = afterEndNode.Previous;
            DLListNode <T> newNode = new DLListNode <T>(value, after, afterEndNode);

            after.SetNext(newNode);
            afterEndNode.SetPrevious(newNode);
        }
Exemplo n.º 3
0
        ///<summary>Creates new instance of <see cref="DLList{T}"></summary>
        public DLList()
        {
            this.size           = 0;
            this.beforeHeadNode = new DLListNode <T>(default(T), null, afterEndNode);
            this.afterEndNode   = new DLListNode <T>(default(T), beforeHeadNode, null);

            //its little tricky, prev and after always points to itself
            //this will help in IEnumerator implementation in DLListIterator class

            beforeHeadNode.SetPrevious(beforeHeadNode);
            beforeHeadNode.SetNext(afterEndNode);
            afterEndNode.SetNext(afterEndNode);
            afterEndNode.SetPrevious(beforeHeadNode);
        }
Exemplo n.º 4
0
        public override void Remove(T value)
        {
            DLListIterator <T> toRemoveIterator;
            int index = GetIndexOf(value, out toRemoveIterator);

            if (index > -1)
            {
                DLListNode <T> toDelete = toRemoveIterator.GetCurrentNode();
                toDelete.Previous.SetNext(toDelete.Next);
                toDelete.Next.SetPrevious(toDelete.Previous);

                //remove references
                toDelete.SetNext(null);
                toDelete.SetPrevious(null);
            }
        }
Exemplo n.º 5
0
 public void SetPrevious(DLListNode <T> previousNode)
 {
     this.Previous = previousNode;
 }
Exemplo n.º 6
0
 public void SetNext(DLListNode <T> nextNode)
 {
     this.Next = nextNode;
 }
Exemplo n.º 7
0
 public DLListNode(T value, DLListNode <T> previous, DLListNode <T> next)
 {
     this.Value    = value;
     this.Previous = previous;
     this.Next     = next;
 }
Exemplo n.º 8
0
 public void Reset()
 {
     this.current = beforeHeadNode;
 }
Exemplo n.º 9
0
 public bool MovePrevious()
 {
     current = current.Previous;
     return(current != beforeHeadNode);
 }
Exemplo n.º 10
0
 public bool MoveNext()
 {
     current = current.Next;
     return(current != afterEndNode);
 }
Exemplo n.º 11
0
 public DLListIterator(DLListNode <T> beforeHeadNode, DLListNode <T> afterEndNode)
 {
     this.beforeHeadNode = beforeHeadNode;
     this.afterEndNode   = afterEndNode;
     this.current        = beforeHeadNode;
 }