示例#1
0
        public void Reverse()
        {
            if (count == 0)
            {
                throw new Exception("List is empty");
            }

            var curNode = _head;
            DoubleHeadedNode <T> nextNode = null;
            DoubleHeadedNode <T> prevNode = null;

            while (curNode != null)
            {
                nextNode     = curNode.Next;
                curNode.Next = prevNode;
                prevNode     = curNode;
                curNode      = nextNode;
                if (curNode != null)
                {
                    curNode.Previous = prevNode;
                }
            }
            _tail      = _head;
            _tail.Next = null;
            _head      = prevNode;
        }
示例#2
0
 public void InsertAtEnd(T value)
 {
     if (_head == null)
     {
         _head = new DoubleHeadedNode <T>(value);
         _tail = _head;
     }
     else
     {
         var newNode = new DoubleHeadedNode <T>(value);
         _tail.Next       = newNode;
         newNode.Previous = _tail;
         _tail            = newNode;
     }
     count++;
 }
示例#3
0
 public void InsertAtFront(T value)
 {
     if (_head == null)
     {
         _head = new DoubleHeadedNode <T>(value);
         _tail = _head;
     }
     else
     {
         var newNode = new DoubleHeadedNode <T>(value);
         newNode.Next   = _head;
         _head.Previous = newNode;
         _head          = newNode;
     }
     count++;
 }
示例#4
0
        public void RemoveFromEnd()
        {
            if (count == 0)
            {
                throw new Exception("List is empty");
            }

            if (count == 1)
            {
                _head = _tail = null;
                count--;
                return;
            }

            _tail      = _tail.Previous;
            _tail.Next = null;
            count--;
        }
示例#5
0
        public void RemoveFromFront()
        {
            if (count == 0)
            {
                throw new Exception("List is empty");
            }

            if (count == 1)
            {
                _head = _tail = null;
                count--;
                return;
            }

            _head          = _head.Next;
            _head.Previous = null;
            count--;
        }
 public DoubleHeadedNode(T value = default(T))
 {
     Value    = value;
     Next     = null;
     Previous = null;
 }