private static void ForEachable() { var ms = new MyStack(); for (var i = 1; i < 130; i++) { ms.Push(i); } Console.WriteLine("My Stack: "); uint ccc = 0; foreach (var i in ms) { Console.Write($"{i}\t"); ccc++; if (ccc % 10 == 0) { Console.WriteLine(); } } Console.WriteLine("\n"); Console.WriteLine($"MyStack: Elements={ms.Count}, Capacity={ms.Capacity}, Last Element={ms.Peek()}"); Console.WriteLine("\n"); var msI = new MyStackG <int>(); for (var i = 1; i < 130; i++) { msI.Push(i); } Console.WriteLine("My Stack<int>: "); ccc = 0; foreach (var i in msI) { Console.Write($"{i}\t"); ccc++; if (ccc % 10 == 0) { Console.WriteLine(); } } Console.WriteLine("\n"); Console.WriteLine($"MyStack: Elements={msI.Count}, Capacity={msI.Capacity}, Last Element={msI.Peek()}"); Console.WriteLine("\n"); var msS = new MyStackG <string>(); for (var i = 1; i < 130; i++) { msS.Push($"item_{i}"); } Console.WriteLine("My Stack<string>: "); ccc = 0; foreach (var i in msS) { Console.Write($"{i} \t"); ccc++; if (ccc % 6 == 0) { Console.WriteLine(); } } Console.WriteLine("\n"); Console.WriteLine($"MyStack: Elements={msS.Count}, Capacity={msS.Capacity}, Last Element={msS.Peek()}"); }
private static void MyStackRunner() { MyStack ms = new MyStack(); ms.Push(1); Console.WriteLine($"MyStack: Elements={ms.Count}, Capacity={ms.Capacity}, Last Element={ms.Peek()}"); ms.Push(2); ms.Push(3); Console.WriteLine($"MyStack: Elements={ms.Count}, Capacity={ms.Capacity}, Last Element={ms.Peek()}"); ms.Push(4); ms.Push(5); ms.Push(6); Console.WriteLine($"MyStack: Elements={ms.Count}, Capacity={ms.Capacity}, Last Element={ms.Peek()}"); Console.WriteLine($"MyStack: Popped element = {ms.Pop()}"); Console.WriteLine($"MyStack: Popped element = {ms.Pop()}"); Console.WriteLine($"MyStack: Popped element = {ms.Pop()}"); Console.WriteLine($"MyStack: Elements={ms.Count}, Capacity={ms.Capacity}, Last Element={ms.Peek()}"); ms.Push(10); ms.Push(11); ms.Push(12); ms.Push(13); ms.Push(14); ms.Push(15); ms.Push(16); ms.Push(17); ms.Push(18); ms.Push(19); ms.Push(20); ms.Push(21); Console.WriteLine($"MyStack: Elements={ms.Count}, Capacity={ms.Capacity}, Last Element={ms.Peek()}"); ms.ListStack(); Console.WriteLine("Empty all elements: "); for (int i = 1; i < ms.Capacity; i++) { Console.Write($"{ms.Pop()} "); } Console.WriteLine(); ms.ListStack(); // Console.WriteLine($"MyStack: Elements={ms.Count}, Capacity={ms.Capacity}, Last Element={ms.Peek()}"); Console.WriteLine($"MyStack: Elements={ms.Count}, Capacity={ms.Capacity}"); Console.WriteLine("Fil stack with elements: "); for (int i = 1; i < 130; i++) { // Console.Write($"{i} "); ms.Push(i); Console.WriteLine($"MyStack: Elements={ms.Count}, Capacity={ms.Capacity}, Last Element={ms.Peek()}"); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine($"MyStack: Elements={ms.Count}, Capacity={ms.Capacity}, Last Element={ms.Peek()}"); Console.WriteLine(); ms.ListStack(); Console.WriteLine(); }