Код: Выделить всё
// Reverse the stack with fun() and fun1()
/* I am unable to understand what is being passed in function fun().
I am not sure about the argument of type stack &s.
Is it a whole stack being passed or just one node? */
void fun1(stack &s, int k)
{
if (s.empty())
{
s.push(k);
return;
}
int t = s.top(); s.pop();
fun1(s, k);
s.push(t);
}
void fun(stack &s)
{
if (s.empty())
{
return;
}
int t = s.top(); s.pop();
fun(s);
fun1(s,t);
}
Подробнее здесь: https://stackoverflow.com/questions/421 ... -in-functi
Мобильная версия