Implementation of queue using two stacks

It is showing output as 1 1 1 1 instead of 1 2 3 4
can u help

hello @shabadsingh
i think that swap function is creating issue.
try to use while loop and copy back all elements from s2 to s1 instead of using swap

check ur updated code here->

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.