Given an integer queue called queue, write a method that will find the max element in the queue. Use the STL to answer this question, you should keep queue elements in the same order and No other data structure can be used other than queue.
/*If you have any query do comment in the comment section else like the solution*/
int findMaxElement(queue<int> myQu) {
int maxm = INT_MIN;
queue<int> tempq;
while(q.size() > 0) {
if(maxm < q.top()) {
maxm = q.top();
}
tempq.push(q.top());
q.pop();
}
//Rebuilding the input queue
while(tempq.size() > 0) {
myQu.push(tempq.top());
tempq.pop();
}
return maxm;
}
Get Answers For Free
Most questions answered within 1 hours.