Find the greater element (queue)


whats wrong in this code?

@tishya_goyal

  1. line 17 should be if(!q.empty() && q.front()>first){
  2. lin 18 should be next=q.front();
  3. comment out line 19
    Here is the updated code: https://ide.codingblocks.com/s/233640
1 Like

but it will check only for next adjacent element ,not in rest of the queue

@tishya_goyal
What’s the purpose of writing break; inside if condition?
your code just stop if (q.front() > first) is true. It won’t print anything

That is ok.But i am asking abt the updated code which u send,it is correct only for adjacent element not for all queue…
for eg. if input is
4 2 5
than output should be 5 5 -1
but it is showing -1 5 -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.