Пример #1
0
 public void InsertAfter(DoubleLinkNode node, DoubleLinkNode newNode)
 {
     newNode.NextNode              = node.NextNode;
     node.NextNode                 = newNode;
     newNode.PreviousNode          = node;
     newNode.NextNode.PreviousNode = newNode;
 }
Пример #2
0
        public DoubleLinkNode InsertLast(DoubleLinkNode newNode)
        {
            // Starting at the head to find the last node in the list
            DoubleLinkNode currentNode  = this.m_Frist;
            var            previousNode = this.m_Frist;

            while (currentNode != null)
            {
                previousNode = currentNode;
                currentNode  = currentNode.NextNode;
            }

            if (previousNode == null)
            {
                this.InsertFirst(newNode);
            }
            else
            {
                // Current node is now pointing to the last node in the list
                previousNode.NextNode = newNode;
                newNode.PreviousNode  = previousNode;
                newNode.NextNode      = null;
            }

            return(newNode);
        }
Пример #3
0
        public void InsertBefore(DoubleLinkNode node, DoubleLinkNode newNode)
        {
            var previousNode = node.PreviousNode;

            newNode.PreviousNode = previousNode;
            newNode.NextNode     = node;

            previousNode.NextNode = newNode;
            node.PreviousNode     = newNode;
        }
Пример #4
0
 public void InsertFirst(DoubleLinkNode newNode)
 {
     if (this.m_Frist == null)
     {
         // This is the first node now
         this.m_Frist = newNode;
     }
     else
     {
         newNode.NextNode          = this.m_Frist;
         this.m_Frist.PreviousNode = newNode;
     }
 }
Пример #5
0
        public DoubleLinkNode GetLastNode()
        {
            DoubleLinkNode currentNode  = this.m_Frist;
            DoubleLinkNode previousNode = this.m_Frist;

            while (currentNode != null)
            {
                previousNode = currentNode;
                currentNode  = currentNode.NextNode;
            }

            return(previousNode);
        }
Пример #6
0
        public DoubleLinkedList DeepCopy()
        {
            var            newList     = new DoubleLinkedList();
            DoubleLinkNode currentNode = this.m_Frist;

            var newNode = currentNode.CopyNode();

            newList.Insert(newNode);

            currentNode = currentNode.NextNode;

            while (currentNode != null)
            {
                newNode = currentNode.CopyNode();
                newList.Insert(newNode);
                currentNode = currentNode.NextNode;
            }

            currentNode = this.GetLastNode();

            return(newList);
        }
Пример #7
0
 public DoubleLinkNode Insert(DoubleLinkNode newNode)
 {
     return(this.InsertLast(newNode));
 }