I am trying to figure out why this works, but when I can the numbers around it doesn't. What the code is suppose to do is have two stacks, the program is suppose to sort in ascending order, which it does, but if I change the:
first.Push(7)
to something like
first.Push(80)
it doesn't work. Can someone explain this, please? Here is what I have:
using System;
using System.Collections;
namespace Project03_03
{
class Program
{
static void Main(string[] args)
{
Stack first = new Stack();
first.Push(50);
first.Push(45);
first.Push(11);
first.Push(7);
Stack second = new Stack();
second.Push(67);
second.Push(65);
second.Push(32);
second.Push(12);
ProcessInOrder(first, second);
Console.WriteLine(
"Press any key to continue...");
Console.ReadKey();
}
static void ProcessInOrder(Stack first,
Stack second)
{
while (first.Count > 0 || second.Count > 0)
{
if (first.Count == 0)
{
Console.WriteLine(second.Pop());
continue;
}
if (second.Count == 0)
{
Console.WriteLine(first.Pop());
continue;
}
if ((int)first.Peek()
>= (int)second.Peek())
{
Console.WriteLine(
second.Pop());
}
else
{
Console.WriteLine(first.Pop());
}
}
}
}
}