public static Stack<int> eigtheen(Stack<Couple> ss)
{
Stack<Couple> sscopy2 = Copy(ss);//for order
Stack<Couple> sscopy3 = Copy(ss);
Stack<int> Order = new Stack<int>();//set order
Stack<Couple> extra = new Stack<Couple>();//set order
int minum = sscopy2.Top().GetNum();//set minum
int g = 0;//min spot
bool b = true;
while (!sscopy3.IsEmpty())
{
minum = sscopy2.Top().GetNum();//get first
while (!sscopy2.IsEmpty())
{
minum = Math.Min(minum, sscopy2.Pop().GetNum());//find the min num currently
}
Order.Push(minum);//push to the bottom the min num;
while (b)
{
if (sscopy3.Top().GetNum() == minum)
{
sscopy3.Pop();//remove the min in order
b = false;
}
else
{
extra.Push(sscopy3.Pop());//save it
}
}
b = true;
while (!extra.IsEmpty())//refill
{
sscopy3.Push(extra.Pop());
}
sscopy2 = Copy(sscopy3);//again but with new numbers
}
Stack<int> final = new Stack<int>();//the final to return
b = true;//making sure
sscopy2 = Copy(ss);//reuse
while (!Order.IsEmpty())//clear all orders
{
while (!sscopy2.IsEmpty() && b)
{
if (Order.Top() == sscopy2.Top().GetNum())
b = false;
else
sscopy2.Pop();
}
for (int i = 0; i < sscopy2.Top().GetAppears(); i++)
{
final.Push(Order.Top());
}
Order.Pop();
sscopy2 = Copy(ss);//get ready for next time
b = true;
}
return final;
}