Mine
public text v1 · immutable public static void Org(Stack<int> a)
{
Stack<int> result = new Stack<int>();
while (a.Count != 0)
result.Push(Max(a));
while (result.Count != 0)
a.Push(result.Pop());
}
public static int Max(Stack<int> a)
{
Stack<int> result = new Stack<int>();
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;
}