public static void Main(string[] args) { Stack<int> stack = new Stack<int>(); stack.Push(1); stack.Push(2); stack.Push(3); Console.WriteLine(stack.Pop()); Console.WriteLine(stack.Peek()); }
public static void Main(string[] args) { SequenceParser.WarningMessage(); var stack = new Stack<int>(); for (int i = 0; i < 200; i++) { stack.Push(i); } Console.WriteLine(new string('=', 60)); Console.WriteLine("PUSHING to stack"); foreach (var st in stack) { Console.Write($"{st} "); } Console.WriteLine(new string('=', 60)); Console.WriteLine("POPING from stack"); for (var i = 0; i < 200; i++) { Console.Write($"{stack.Pop()} "); } }
public static void Main() { Stack<int> stack = new Stack<int>(); stack.Push(1); stack.Push(2); stack.Push(3); stack.Push(4); stack.Push(5); while (stack.Count > 0) { Console.Write(stack.Pop()); } Console.WriteLine(); }
public static void Main() { // The initial value of the array is 4. If we add 5 elements it should resize to 8. var stack = new Stack<int>(); Console.WriteLine("Adding 1,2,3,4,5"); stack.Push(1); stack.Push(2); stack.Push(3); stack.Push(4); stack.Push(5); Console.WriteLine("Peeking last added number: {0}", stack.Peek()); Console.WriteLine("Popping number: {0}", stack.Pop()); Console.WriteLine("Popping number: {0}", stack.Pop()); Console.WriteLine("Peeking number: {0}", stack.Peek()); Console.WriteLine("Pushing number 6"); stack.Push(6); Console.WriteLine("Peeking number: {0}", stack.Peek()); }
public static void Main(string[] args) { var stack = new Stack<int>(); Console.WriteLine(stack); stack.Push(1); Console.WriteLine(stack); stack.Push(2); Console.WriteLine(stack); stack.Push(3); Console.WriteLine(stack); stack.Push(4); Console.WriteLine(stack); stack.Push(5); Console.WriteLine(stack); stack.Push(6); Console.WriteLine(stack); Console.WriteLine("Containes(4): {0}", stack.Contains(4)); Console.WriteLine("Containes(7): {0}", stack.Contains(7)); // stack.Clear(); // Console.WriteLine(stack); stack.Pop(); stack.Pop(); stack.Pop(); stack.Pop(); Console.WriteLine(stack); stack.TrimExcess(); Console.WriteLine(stack); stack.Pop(); Console.WriteLine(stack); Console.WriteLine("Peek() => {0}\n", stack.Peek()); Console.WriteLine(stack); // stack.Pop(); // Console.WriteLine(stack); // stack.Pop(); // Console.WriteLine(stack); }