static void Main(string[] args) { ExtendedStack myStack1 = new ExtendedStack(); ExtendedStack myStack2 = new ExtendedStack(); myStack1.Push(1); myStack1 = myStack1 + (-2); Console.WriteLine("myStack1 is empty? {0}\nmyStack2 is empty? {1}\n", myStack1 ? "true" : "false", myStack2 ? "true" : "false"); myStack2.Push(0); myStack2 = myStack2 + 5; ExtendedStack myStack3 = myStack1 > myStack2; //Testing extension method for string string testString = "What! Are? You doing."; Console.WriteLine(testString + "\n" + string.Format("Sentences: {0}\n", testString.WordCount())); myStack3 = myStack3 + 7; Console.WriteLine("Medium element = " + Static.MediumElemStack(myStack3) + "\n"); Console.WriteLine(myStack3.Pop()); Console.WriteLine(myStack3.Pop()); myStack3--; Console.WriteLine(myStack3.Pop()); Console.ReadKey(); }
public static int GetMinElement(ExtendedStack stack) { int[] temp = new int[stack.Count]; for (int i = temp.Length - 1; i >= 0; i--) { temp[i] = stack.Pop(); } return(temp.Min()); }
public static ExtendedStack IncrementN(ExtendedStack stack, int N) { int[] temp = new int[stack.Count]; for (int i = temp.Length - 1; i >= 0; i--) { temp[i] = stack.Pop(); } for (int i = 0; i < temp.Length; i++) { stack.Push(temp[i] + N); } return(stack); }
// > - копирование одного стека в другой с сортировкой в возрастающем порядке public static ExtendedStack operator >(ExtendedStack stack1, ExtendedStack stack2) { ExtendedStack result = new ExtendedStack(); while (stack1.Count != 0) { result = result + stack1.Pop(); } while (stack2.Count != 0) { result = result + stack2.Pop(); } result.storage.Sort(); return(result); }
public static int MediumElemStack(ExtendedStack stack) { int medium = stack.Count / 2; int[] temp = new int[stack.Count]; for (int i = temp.Length - 1; i >= 0; i--) { temp[i] = stack.Pop(); } for (int i = 0; i < temp.Length; i++) { stack.Push(temp[i]); } return(temp[medium]); }