Udemy: Master Coding Interview - Stacks + Queues - #116

Run Settings
LanguageC#
Language Version
Run Command
using System; class Stack { int length = 0; string[] values; static void Main() { Console.WriteLine("Hello World!"); Stack myStack = new Stack(); Console.WriteLine("myStack: " + myStack.ToString()); myStack.Push("Discord"); Console.WriteLine("myStack: " + myStack.ToString()); myStack.Push("Udemy"); Console.WriteLine("myStack: " + myStack.ToString()); myStack.Push("Google"); Console.WriteLine("myStack: " + myStack.ToString()); Console.WriteLine("myStack.Peek(): " + myStack.Peek()); Console.WriteLine("myStack: " + myStack.ToString()); myStack.Pop(); Console.WriteLine("myStack: " + myStack.ToString()); myStack.Pop(); Console.WriteLine("myStack: " + myStack.ToString()); myStack.Pop(); Console.WriteLine("myStack: " + myStack.ToString()); } public Stack() { this.values = new string[50]; } public void Push(string value) { this.values[this.length] = value; this.length++; } public string Pop() { if (this.length > 0) { this.length--; return this.values[this.length]; } return null; } public string Peek() { if (this.length > 0) { return this.values[this.length-1]; } return null; } public string ToString() { string s = "{"; int count = 0; for (int i = this.length-1; i >= 0; i--) { if (count > 0) { s += ", "; } count++; s += "" + this.values[i]; } s += "}"; return s; } }
Editor Settings
Theme
Key bindings
Full width
Lines