can you please explain the transfer fucntion
void transfer(stack&s1,stack&s2,int n){
for(int i=0;i<n;i++){
s2.push(s1.top());
s1.pop();
}
}
can you please explain the transfer fucntion
void transfer(stack&s1,stack&s2,int n){
for(int i=0;i<n;i++){
s2.push(s1.top());
s1.pop();
}
}
Hey @chitranshanmol07
So we have 2 stcks say s2 is empty and s1 contains 1 2 3 4 5 6 7 here 7 is top side
Now acc to our loop we do this
Initially
s1-> 1 2 3 4 5 6 7
s2 ->
1st iteration
s1-> 1 2 3 4 5 6
s2-> 7
2nd iteration
s1-> 1 2 3 4 5
s2-> 7 6
3rd iteration
s1-> 1 2 3 4
s2-> 7 6 5
and so on
7th iteration
2nd iteration
s1->
s2-> 7 6 5 4 3 2 1
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.