private static void Method4() { MaxStack stack = new MaxStack(); stack.Push(5); stack.PeekMax(); stack.Pop(); }
private static void Method1() { MaxStack stack = new MaxStack(); stack.Push(5); stack.Push(1); stack.Push(5); stack.Top(); //-> 5 stack.PopMax(); //-> 5 stack.Top(); //-> 1 stack.PeekMax(); //-> 5 stack.Pop(); //-> 1 stack.Top(); //-> 5 }
private static void Method3() { MaxStack stack = new MaxStack(); stack.Push(74); stack.PopMax(); stack.Push(89); stack.Push(67); stack.PopMax(); stack.Pop(); stack.Push(61); stack.Push(-77); stack.PeekMax(); stack.PopMax(); }
static void Main(string[] args) { int range = 100; int tries = 10; var stack = new MaxStack(); var rnd = new Random(); for (int i = 0; i < tries; i++) { int j = rnd.Next(range); stack.Push(j); Console.Write($"push: {j} max: {stack.Max()}\n"); } Console.WriteLine(); while (stack.Size() > 0) { Console.Write($"max: {stack.Max()} pop: {stack.Pop()}\n"); } Console.WriteLine(); Console.ReadKey(); }