public static void Org(Stack a) { Stack result = new Stack(); while (a.Count != 0) result.Push(Max(a)); while (result.Count != 0) a.Push(result.Pop()); } public static int Max(Stack a) { Stack result = new Stack(); int max = int.MinValue; while (a.Count != 0) { if (a.Peek() > max) max = a.Peek(); result.Push(a.Pop()); } while (result.Count != 0) { if (result.Peek() != max) a.Push(result.Peek()); result.Pop(); } return max; }