Пример #1
0
        public void DeleteAt(int index) // 0th index
        {
            if (index == 0)
            {
                (HeadNode.NextNode as DoubleNode <T>).PreviousNode = null;
                HeadNode = (DoubleNode <T>)HeadNode.NextNode;
                return;
            }

            var refNode = HeadNode;

            for (int i = 0; i < index - 1; i++)
            {
                refNode = refNode.NextNode as DoubleNode <T>;
            }

            refNode.NextNode = refNode.NextNode.NextNode;
            (refNode.NextNode as DoubleNode <T>).PreviousNode = refNode;
        }
Пример #2
0
        public void AddNode(T value)
        {
            DoubleNode <T> newNode = new DoubleNode <T>(value);

            if (HeadNode == null)
            {
                HeadNode = newNode;
                return;
            }
            var refNode = HeadNode;

            while (refNode.NextNode != null)
            {
                refNode = (DoubleNode <T>)refNode.NextNode;
            }

            newNode.PreviousNode = refNode;
            refNode.NextNode     = newNode;
        }