Exemplo n.º 1
0
        public void Swap(DLinkNode node)
        {
            DLinkNode tempNode = new DLinkNode();

            if (this.Prev == node || this.Next == node)
            {
                DLinkNode frontNode, backNode;
                if (this.Next == node)
                {
                    frontNode = this;
                    backNode  = node;
                }
                else
                {
                    frontNode = node;
                    backNode  = this;
                }

                if (backNode.Next != null)
                {
                    tempNode.Next = backNode.Next;
                }                 //else nothing

                if (frontNode.Prev != null)
                {
                    frontNode.Prev.Next = backNode;
                }
                //if and else both
                backNode.Prev = frontNode.Prev;

                backNode.Next  = frontNode;
                frontNode.Prev = backNode;

                if (tempNode.Next != null)
                {
                    tempNode.Next.Prev = frontNode;
                }
                //if and else both
                frontNode.Next = tempNode.Next;
            }
            else
            {
                if (node.Prev != null)
                {
                    tempNode.Prev = node.Prev;
                }                 //else nothing
                if (node.Next != null)
                {
                    tempNode.Next = node.Next;
                }                 //else nothing


                if (this.Prev != null)
                {
                    this.Prev.Next = node;
                }
                //if and else both
                node.Prev = this.Prev;

                if (this.Next != null)
                {
                    this.Next.Prev = node;
                }
                //if and else both
                node.Next = this.Next;


                if (tempNode.Prev != null)
                {
                    tempNode.Prev.Next = this;
                }
                //if and else both
                this.Prev = tempNode.Prev;

                if (tempNode.Next != null)
                {
                    tempNode.Next.Prev = this;
                }
                //if and else both
                this.Next = tempNode.Next;
            }
        }
Exemplo n.º 2
0
 public Enumerator(DLinkNode dLinkNode)
 {
     localDLN = dLinkNode;
     Current  = dLinkNode;
     isFirst  = true;
 }