/// <summary> /// Helper method /// </summary> private void AlternateNodes() { int depth = Count; bool even = Count % 2 == 0; Stack tempStack = new Stack(); for (int i = 0; i < depth; i++) { if (even) { tempStack.Push(StackTwo.Pop()); } else { tempStack.Push(StackOne.Pop()); } } for (int j = 0; j < depth; j++) { if (even) { StackOne.Push(tempStack.Pop()); } else { StackTwo.Push(tempStack.Pop()); } } }
/// <summary> /// Dequeues a node from the queue and returns its value. /// </summary> /// <returns> /// string: the string value of the dequeued Node /// </returns> public string Dequeue() { try { string returnValue = StackOneLastPopped ? StackTwo.Pop() : StackOne.Pop(); StackOneLastPopped = !StackOneLastPopped; Count--; return(returnValue); } catch (NullReferenceException e) { throw e; } }
/// <summary> /// Dequeue method /// </summary> /// <returns>string of returned node</returns> public string Dequeue() { try { if (Count % 2 == 0) { return(StackOne.Pop()); } else { return(StackTwo.Pop()); } } catch (NullReferenceException e) { throw new Exception(""); } }