コード例 #1
0
        public void InsertLast(int data)
        {
            if (_head == null)
            {
                _head = new DoubleLinkedListNode(data);
                return;
            }

            var temp = _head;

            while (temp.Next != null)
            {
                temp = temp.Next;
            }

            temp.Next = new DoubleLinkedListNode(data, null, temp);
        }
コード例 #2
0
        public void Reverse()
        {
            var current = _head;
            DoubleLinkedListNode temp = null;

            while (current != null)
            {
                temp         = current.Prev;
                current.Prev = current.Next;
                current.Next = temp;
                current      = current.Prev;
            }

            if (temp != null)
            {
                _head = temp.Prev;
            }
        }
コード例 #3
0
        public void DeleteFromLast()
        {
            if (_head == null)
            {
                throw new NullReferenceException();
            }

            if (_head.Next == null)
            {
                _head = null;
                return;
            }

            var temp = _head;

            while (temp.Next.Next != null)
            {
                temp = temp?.Next;
            }

            temp.Next = null;
        }
コード例 #4
0
 public DoublyLinkedList(DoubleLinkedListNode head = null)
 {
     _head = head;
 }