Example #1
0
        public void Addright(DLL <T> target)
        {
            if (this.right == null)
            {
                this.right = target;
            }
            else
            {
                target.left  = this;
                target.right = this.right;

                this.right.left = target;
                this.right      = target;
            }
        }
Example #2
0
 public void Delete()
 {
     //if (right==null&&left==null)//左右两个null
     //{
     //    //这种情况不存在,链表  最少要有两个
     //}
     if (left == null && right != null)//  在左有一个null
     {
         right.left = null; right = null;
     }
     else if (left != null && right == null)// 在右有一个null
     {
         left.right = null; left = null;
     }
     else//无null
     {
         right.left = left;
         left.right = right;
     }
 }
Example #3
0
        public static void Swap(DLL <T> theleft, DLL <T> theright)//两个对象之间交换 静态更好
        {
            //当左右连在一起
            if (theright.left == theleft)
            {  ////思路0
                //修改槽
                if (theleft.left != null)
                {
                    theleft.left.right = theright;
                }                                  /*else   {  }*/
                if (theright.right != null)
                {
                    theright.right.left = theleft;
                }                                  /*else   {  }*/
                //备份
                DLL <T> newright = theright, newleft = theleft;
                //修改者
                //
                theleft.left = theright;
                //if (newright.right == null)
                //{ theleft.right = null; }
                //else
                /* { */
                theleft.right = newright.right; /*}*/
                //
                theright.right = theleft;
                //if (newleft.left == null)
                //{ theright.left = null; }
                //else
                /* { */
                theright.left = newleft.left; /*}*/

                ////思路2
                //DLL newright = theright, newleft = theleft;
                //newright.left = theleft.left;newright.right = theleft.right;
                //newleft.left = theright.left;newleft.right = theright.right;
                //theright = newright;
                //theleft = newleft;
                ////思路1
                //DLL newright = theright;
                //theright.Delete();
                //theleft.Addleft(theright);
                //theleft.Addright(newright);
            }
            else //当左者和右者不连在一起
            {
                //修改右槽
                theright.left.right = theleft;
                if (theright.right != null)
                {
                    theright.right.left = theleft;
                }
                //else {  }

                //修改左槽
                theleft.right.left = theright;
                if (theleft.left != null)
                {
                    theleft.right.left = theright;
                }
                //else { }

                //修改左者
                DLL <T> backup_left = theleft;  //备份
                theleft.left = theright.left;
                if (theright.right != null)
                {
                    theleft.right = theright.right;
                }
                else
                {
                    theleft.right = null;
                }

                //修改右者
                theright.right = backup_left.right;
                if (backup_left.left != null)
                {
                    theright.left = backup_left.left;
                }
                else
                {
                    theright.left = null;
                }
            }
        }