Stack using queue

#include
#include
using namespace std;
template
class stack
{
queueq1,q2;
public:
void push(T x)
{
q1.push(x);
}
void pop()
{
if(q1.empty())
return;
while(q1.size()>1)
{
T element=q1.front();
q2.push(element);
q1.pop();
}
q1.pop();
}
T top()
{
while(q1.size()>1)
{
T element=q1.front();
q2.push(element);
q1.pop();
}
T element=q1.front();
q1.pop();
q2.push(element);
swap(q1,q2);
return (element);
}
int size()
{
return q1.size()+q2.size();
}
bool empty()
{
return size()==0;
}
};
int main()
{
stacks;
s.push(1);
s.push(2);
s.push(3);
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
return 0;
}

please correct the error in my code its terminating

Please save your code on ide.codingblocks.com and then share its link.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.