Example #1
0
        public void AddLast(T value)
        {
            MyLinkedListNode <T> node = new MyLinkedListNode <T>(value);

            if (Count == 0)
            {
                _head = node;
            }
            else
            {
                _tail.Next = node;

                // До:    Head -> 3  5 -> null
                // После:Head -> 3  5  7 -> null
                // 7.Previous = 5
                node.Previous = _tail;
            }

            _tail = node;
            count++;
        }
Example #2
0
        public void RemoveLast()
        {
            if (Count != 0)
            {
                if (Count == 1)
                {
                    _head = null;
                    _tail = null;
                }
                else
                {
                    // До:    Head --> 3 --> 5 --> 7
                    //        Tail = 7
                    // После: Head --> 3 --> 5 --> null
                    //        Tail = 5
                    // Обнуляем 5.Next
                    _tail.Previous.Next = null;
                    _tail = _tail.Previous;
                }

                count--;
            }
        }
Example #3
0
        public void RemoveFirst()
        {
            if (Count != 0)
            {
                // До:    Head -> 3  5
                // После: Head -------> 5

                // Head -> 3 -> null
                // Head ------> null
                _head = _head.Next;

                count--;

                if (Count == 0)
                {
                    _tail = null;
                }
                else
                {
                    // 5.Previous было 3; теперь null.
                    _head.Previous = null;
                }
            }
        }