Exemple #1
0
        public void Insert(T data, int location)
        {
            if (Head == null)
            {
                Head = Tail = new DoubleLinkedListNode <T>(data, null, null);

                return;
            }

            var current = Head;
            var index   = 1;

            while (current.NextNode != null && index < location)
            {
                current = current.NextNode;

                index++;
            }

            var newInsertNode = new DoubleLinkedListNode <T>(data, current.NextNode, current);

            current.NextNode = newInsertNode;
        }
Exemple #2
0
        public void Append(T data)
        {
            var newTailNode = new DoubleLinkedListNode <T>(data, null, null);

            if (Head == null)
            {
                Head = Tail = newTailNode;

                return;
            }

            var current = Head;

            while (current.NextNode != null)
            {
                current = current.NextNode;
            }

            current.NextNode = newTailNode;

            newTailNode.PreviousNode = current;

            Tail = newTailNode;
        }
Exemple #3
0
        }                               // TODO: Implement

        public DoubleLinkedList(DoubleLinkedListNode <T> head, DoubleLinkedListNode <T> tail)
        {
            Head = head;
            Tail = tail;
        }
Exemple #4
0
 public DoubleLinkedListNode(T data, DoubleLinkedListNode <T> nextNode, DoubleLinkedListNode <T> previousNode)
 {
     Data         = data;
     NextNode     = nextNode;
     PreviousNode = previousNode;
 }