queue stl Question 10

Last Updated :
Discuss
Comments

What will be the output of the following C++ program?

#include <iostream>
#include <queue>
using namespace std;
int main()
{
queue<int> myqueue;
myqueue.push(80);
myqueue.push(70);
myqueue.push(60);
myqueue.push(50);


if (myqueue.front() > myqueue.back()) {
 cout << myqueue.front() - myqueue.back();
}
else if (myqueue.front() < myqueue.back()) {
 cout << myqueue.back() - myqueue.front();
}
else
 cout << "0";
}

50

70

30

130

Share your thoughts in the comments