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)); }
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)); }
public PersistentQueue <T> Push(T element) { if (!recopy) { PersistentStack <T> Ln = L.Push(element); PersistentQueue <T> Q = new PersistentQueue <T>(Ln, Li, R, Ri, S, recopy, toCopy, copied); return(Q.CheckRecopy()); } else { PersistentStack <T> Lni = Li.Push(element); PersistentQueue <T> Q = new PersistentQueue <T>(L, Lni, R, Ri, S, recopy, toCopy, copied); return(Q.CheckNormal()); } }
public PersistentQueue <T> Push(T element) { if (!IsRecopy) { PersistentStack <T> newLeft = Left.Push(element); PersistentQueue <T> newQueue = new PersistentQueue <T>(newLeft, LeftRecopy, Right, RightRecopy, TempRight, IsRecopy, ToCopy, Copied); return(newQueue.CheckRecopy()); } else { PersistentStack <T> newLeftRecopy = LeftRecopy.Push(element); PersistentQueue <T> newQueue = new PersistentQueue <T>(Left, newLeftRecopy, Right, RightRecopy, TempRight, IsRecopy, ToCopy, Copied); return(newQueue.CheckNormal()); } }