/// <summary> /// 1つ目のStackから2つ目のStackへの移動処理を行う /// </summary> private void MoveCheck() { if (SecondStack.Count == 0) { while (FirstStack.Count > 0) { SecondStack.Push(FirstStack.Pop()); } } }
/// <summary> /// extracts a value from the PseudoQueue, using a first-in, first-out approach. /// </summary> /// <param name="value"></param> public int PseudoQueueDequeue() { if (FirstStack.IsEmpty()) { throw new Exception("Nothing in PsuedoQueue"); } while (FirstStack.Top.Next != null) { SecondStack.Push(FirstStack.Pop()); } int dequeuedValue = FirstStack.Pop(); while (!SecondStack.IsEmpty()) { FirstStack.Push(SecondStack.Pop()); } return(dequeuedValue); }
/// <summary> /// inserts value into the PseudoQueue, using a first-in, first-out approach. /// </summary> /// <param name="value"></param> public void PseudoQueueEnqueue(int value) { if (FirstStack.IsEmpty()) { FirstStack.Push(value); } else { while (!FirstStack.IsEmpty()) { SecondStack.Push(FirstStack.Pop()); } FirstStack.Push(value); while (!SecondStack.IsEmpty()) { FirstStack.Push(SecondStack.Pop()); } } }