public void Push4Elements_ToArray_ShouldWorkCorrectly() { //Arrange var array = new int[] { 3, 5, -2, 7 }; var stack = new ArrayStack <int>(); //Act for (int i = 0; i < array.Length; i++) { stack.Push(array[i]); } var arrayFromStack = stack.ToArray(); Array.Reverse(array); //Assert CollectionAssert.AreEqual(array, arrayFromStack); }
private static void Main(string[] args) { var stack = new ArrayStack <int>(); for (int i = 0; i < 50; i++) { stack.Push(i); } Console.WriteLine(stack.Pop()); Console.WriteLine(stack.Count); Console.WriteLine(stack.Pop()); int[] arr = stack.ToArray(); Console.WriteLine(arr[0]); Console.WriteLine(arr.Length); }
static void Main(string[] args) { //Create a Random Number Generator Random num = new Random(); //Create an ArrayList ArrayList myStack = new ArrayList(); //Create a Array stack instance ArrayStack theStack = new ArrayStack(myStack, 10); WriteLine("Try To Pop An Empty Stack"); theStack.Pop(); //Fill the stack WriteLine("\nFill The Stack With Values"); for (int i = 0; i < theStack.Capacity; i++) { theStack.Push(num.Next(0, 10)); }//End for loop //Print the stack for comparison PrintStack(theStack); //Try out the peek method WriteLine($"\nPeek Method Returned: {theStack.Peek().ToString()}"); //Try to push past capacity WriteLine("\nTry To Push Over Capacity"); theStack.Push(22); //Tryout the pop method WriteLine($"\nPop Method Removed: {theStack.Peek()} From The Stack"); theStack.Pop(); WriteLine($"\nPop Method Removed: {theStack.Peek()} From The Stack"); theStack.Pop(); //Print for comparison PrintStack(theStack); //Try to push again WriteLine("\nPushing Value '22' To The Stack"); theStack.Push(22); //Try to push again WriteLine("\nPushing Value '33' To The Stack"); theStack.Push(33); //Try to push again WriteLine("\nPushing Value '44' To The Stack"); theStack.Push(44); //Print for comparison PrintStack(theStack); //Try out the peek method WriteLine($"\nPeek Method Returned: {theStack.Peek().ToString()}"); //Readkey to stop the program ReadKey(); }