public T[] GetPreOrderValues() { T[] resultArray = new T[nodesCount]; if (nodesCount > 0) { aStack <RBNode <T> > stack = new aStack <RBNode <T> >(); stack.Push(root); RBNode <T> current; int index = 0; while (stack.IsEmpty()) { current = stack.Pop(); if (current != null) { resultArray[index] = current.Value; stack.Push(current.Left); stack.Push(current.Right); } } } else { resultArray = new T[0]; } return(resultArray); }
public void PushOneElement_PopElement_ElementAreSame() { aStack <object> stack = new aStack <object>(); object testElement = new object(); stack.Push(testElement); object popedElement = stack.Pop(); Assert.AreEqual(testElement, popedElement); }
public void PushTenElements_Pop11Elements_ThrowsException() { aStack <object> stack = new aStack <object>(); for (int i = 0; i < 10; i++) { stack.Push(new object()); } for (int i = 0; i < 11; i++) { stack.Pop(); } }
public void Push100Elements_PopSame100Elements() { object[] testArray = new object[100]; for (int i = 0; i < 100; i++) { testArray[i] = new object(); } aStack <object> stack = new aStack <object>(); for (int i = 0; i < 100; i++) { stack.Push(testArray[i]); } bool allAreSame = true; for (int i = 0; i < 100; i++) { allAreSame = allAreSame && (testArray[99 - i] == stack.Pop()); } Assert.IsTrue(allAreSame); }
public void Pop_EmptyStack_ThrowsException() { aStack <object> stack = new aStack <object>(); stack.Pop(); }