If I do not to want to create a new container in order to do so?
It can be easily done using recursion you just need to know when to re-add the next element
For Stack
void print(stack<char> &s)
{
if(s.empty())
{
cout << endl;
return;
}
char x= s.top();
s.pop();
print(s);
s.push(x);
cout << x << " ";
}
And this one is For Queue
void print(queue<char> &s,int num)
{
if(!num)
{
cout << endl;
return;
}
char x= s.front();
s.pop();
cout << x << " ";
s.push(x);
print(s,--num);
}
Good Luck