what is the output in 7th question when the queue is descending order??
Stack and queue quiz
please tell me the question title u are talking about
or attach a ss of the same
My confusion is of queue is descending then it will go infinite??
n^2 time will be consumed
u can code it
it works fine
#include<bits/stdc++.h>
using namespace std;
int main(){
queueq;
q.push(9);q.push(8);q.push(7);q.push(6);
stacks;
int count = 0;
while(!q.empty()){
count+=1;
cout << count;
if(s.empty() or s.top()<= q.front()){
int x = q.front();
q.pop();
s.push(x);
}else{
q.push(s.top());
s.pop();
}
}
}
Yes mam after dry running for input 3 i got it thanks…
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.
