Пример #1
0
 public PersistentQueue <T> Pop()
 {
     if (!IsRecopy)
     {
         PersistentStack <T> newRight = Right.Pop();
         PersistentQueue <T> newQueue = new PersistentQueue <T>(Left, LeftRecopy, newRight, RightRecopy, TempRight, IsRecopy, ToCopy, Copied);
         return(newQueue.CheckRecopy());
     }
     else
     {
         PersistentStack <T> newRightRecopy = RightRecopy.Pop();
         PersistentStack <T> newRight       = Right;
         Int32 curToCopy = ToCopy;
         if (ToCopy > 0)
         {
             --curToCopy;
         }
         else
         {
             newRight = Right.Pop();
         }
         PersistentQueue <T> newQueue = new PersistentQueue <T>(Left, LeftRecopy, newRight, newRightRecopy, TempRight, IsRecopy, curToCopy, Copied);
         return(newQueue.CheckNormal());
     }
 }
Пример #2
0
 public PersistentQueue <T> Pop()
 {
     if (!recopy)
     {
         PersistentStack <T> Rn = R.Pop();
         PersistentQueue <T> Q  = new PersistentQueue <T>(L, Li, Rn, Ri, S, recopy, toCopy, copied);
         return(Q.CheckRecopy());
     }
     else
     {
         PersistentStack <T> Rni = Ri.Pop();
         PersistentStack <T> Rn  = R;
         Int32 curCopy           = toCopy;
         if (toCopy > 0)
         {
             --curCopy;
         }
         else
         {
             Rn = Rn.Pop();
         }
         PersistentQueue <T> Q = new PersistentQueue <T>(L, Li, Rn, Rni, S, recopy, curCopy, copied);
         return(Q.CheckNormal());
     }
 }
Пример #3
0
        private PersistentQueue <T> AdditionalsOperations()
        {
            Int32 toDo = 3;

            PersistentStack <T> newLeft       = Left;
            PersistentStack <T> newLeftRecopy = LeftRecopy;
            PersistentStack <T> newRight      = Right;
            PersistentStack <T> newTempRight  = TempRight;

            Boolean newCopied = Copied;
            Int32   newToCopy = ToCopy;

            while (!newCopied && toDo > 0 && newRight.Count > 0)
            {
                T x = newRight.Peek();
                newRight = newRight.Pop();

                newTempRight = newTempRight.Push(x);

                --toDo;
            }

            while (toDo > 0 && newLeft.Count > 0)
            {
                newCopied = true;

                T x = newLeft.Peek();
                newLeft = newLeft.Pop();

                newRight = newRight.Push(x);

                --toDo;
            }

            while (toDo > 0 && newTempRight.Count > 0)
            {
                T x = newTempRight.Peek();
                newTempRight = newTempRight.Pop();

                if (newToCopy > 0)
                {
                    newRight = newRight.Push(x);
                    --newToCopy;
                }
                --toDo;
            }

            if (newTempRight.Count == 0)
            {
                PersistentStack <T> temp = newLeft;
                newLeft       = newLeftRecopy;
                newLeftRecopy = temp;
            }

            return(new PersistentQueue <T>(newLeft, newLeftRecopy, newRight, RightRecopy, newTempRight, IsRecopy, newToCopy, newCopied));
        }
Пример #4
0
        private PersistentQueue <T> AdditionalsOperations()
        {
            Int32 toDo = 3;

            PersistentStack <T> Ln  = L;
            PersistentStack <T> Lni = Li;
            PersistentStack <T> Rn  = R;
            PersistentStack <T> Sn  = S;

            Boolean curCopied = copied;
            Int32   curCopy   = toCopy;

            while (!curCopied && toDo > 0 && Rn.Count > 0)
            {
                T x = Rn.Peek();
                Rn = Rn.Pop();
                Sn = Sn.Push(x);
                --toDo;
            }

            while (toDo > 0 && Ln.Count > 0)
            {
                curCopied = true;
                T x = Ln.Peek();
                Ln = Ln.Pop();
                Rn = Rn.Push(x);
                --toDo;
            }

            while (toDo > 0 && Sn.Count > 0)
            {
                T x = Sn.Peek();
                Sn = Sn.Pop();
                if (curCopy > 0)
                {
                    Rn = Rn.Push(x);
                    --curCopy;
                }
                --toDo;
            }

            if (Sn.Count == 0)
            {
                PersistentStack <T> t = Ln;
                Ln  = Lni;
                Lni = t;
            }

            return(new PersistentQueue <T>(Ln, Lni, Rn, Ri, Sn, recopy, curCopy, curCopied));
        }