public void StackEmptyandGetCount() { int maxSize = 100; var myStack = new MyStack(maxSize); Assert.AreEqual(0, myStack.GetCount()); }
public void StackPushGetCount() { int maxSize = 100; var myStack = new MyStack(maxSize); myStack.Push(1); Assert.AreEqual(1, myStack.GetCount()); }
public string ToPostfix(string inFix) { MyStack postFix = new MyStack(inFix.Length); MyStack operators = new MyStack(inFix.Length); char popUpOperator; foreach (char c in inFix.ToCharArray()) { if (Char.IsLetterOrDigit(c)) { postFix.Push(c); } else if (c == '(') { operators.Push(c); } else if (c == ')') { popUpOperator = (char)operators.Pop(); while (popUpOperator != '(') { postFix.Push(popUpOperator); popUpOperator = (char)operators.Pop(); } } else { if (!(operators.IsEmpty()) && HigherOperatorPriority((char)operators.Peek(), c)) { popUpOperator = (char)operators.Pop(); while (HigherOperatorPriority(popUpOperator, c)) { postFix.Push(popUpOperator); if (operators.IsEmpty()) { break; } popUpOperator = (char)operators.Pop(); } operators.Push(c); } else { operators.Push(c); } } } while (operators.GetCount() > 0) { popUpOperator = (char)operators.Pop(); postFix.Push(popUpOperator); } return(postFix.ItemToString()); }
public void StackPush3ItemGetCount() { int maxSize = 100; var myStack = new MyStack(maxSize); myStack.Push(1); myStack.Push("1"); myStack.Push("A"); Assert.AreEqual(3, myStack.GetCount()); }
public void StackPush3ItemAndPopGetCount() { int maxSize = 100; var myStack = new MyStack(maxSize); myStack.Push(1); myStack.Push("1"); myStack.Push("A"); var obj = myStack.Pop(); Assert.AreEqual("A", obj); Assert.AreEqual(2, myStack.GetCount()); }