コード例 #1
0
ファイル: DoubleLinked.cs プロジェクト: Zoulily97/Csharp
        //交换节点
        public void Swap(DoubleLinked <T> targetNode)
        {
            DoubleLinked <T> prethis  = this.Previous;
            DoubleLinked <T> nextthis = this.Next;

            this.Delete();
            if (nextthis == targetNode)
            {
                targetNode.AddAfter(this);
            }
            else if (prethis == targetNode)
            {
                targetNode.InsretBefor(this);
            }
            else /*if (nextthis != targetNode && prethis != targetNode)*/
            {
                targetNode.AddAfter(this);
                targetNode.Delete();
                if (prethis == null)
                {
                    nextthis.InsretBefor(targetNode);
                }
                else
                {
                    prethis.AddAfter(targetNode);
                }
            }
        }
コード例 #2
0
        //删除当前节点
        public void Delete()
        { //  1 2- 【3】
            DoubleLinked oldPre = this.Previous;
            DoubleLinked oldNex = this.Next;

            if (oldPre != null)
            {
                oldPre.Next = oldNex;
            }
            if (oldNex != null)
            {
                oldNex.Previous = oldPre;
            }
            this.Previous = this.Next = null;



            //if (this.Previous != null && this.Next != null)
            //{
            //    this.Previous.Next = this;
            //    this.Next.Previous = this;
            //}
            //else if (this.Previous == null)
            //{
            //   Next= Previous = null;
            //}
            //else
            //{
            //    Next = Previous = null;
            //}
        }
コード例 #3
0
ファイル: DoubleLinked.cs プロジェクト: Zoulily97/Csharp
 //在该节点前插入节点node
 public void InsretBefor(DoubleLinked <T> node)
 {
     if (this.Previous != null)
     {
         node.Previous      = this.Previous;
         this.Previous.Next = node;
     }
     node.Next     = this;
     this.Previous = node;
 }
コード例 #4
0
ファイル: DoubleLinked.cs プロジェクト: Zoulily97/Csharp
        //在节点后插入节点node
        public void AddAfter(DoubleLinked <T> node)
        {
            //1 2] 3 4
            if (this.Next != null)
            {
                node.Next = this.Next;
                //  node.Previous = this;
                this.Next.Previous = node;
                //  this.Next = node;
            }

            node.Previous = this;
            this.Next     = node;
        }
コード例 #5
0
ファイル: DoubleLinked.cs プロジェクト: Zoulily97/Csharp
        //删除当前节点
        public void Delete()
        { //  1 2- 【3】
            DoubleLinked <T> oldPre = this.Previous;
            DoubleLinked <T> oldNex = this.Next;

            if (oldPre != null)
            {
                oldPre.Next = oldNex;
            }
            if (oldNex != null)
            {
                oldNex.Previous = oldPre;
            }
            this.Previous = this.Next = null;
        }
コード例 #6
0
ファイル: DoubleLinked.cs プロジェクト: Zoulily97/Csharp
 public NodeIEnumerator(DoubleLinked <T> node)
 {
     Current = node;
 }