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)); }
public T Peek() { if (!recopy) { return(R.Peek()); } else { return(Ri.Peek()); } }
public T Peek() { if (!IsRecopy) { return(Right.Peek()); } else { return(RightRecopy.Peek()); } }
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)); }