Questions and Answers
- What is the output of this program?
#include <iostream>
#include <stack>
using namespace std;
int main ()
{
stack<int> StackData;
StackData.push(25);
StackData.push(45);
StackData.top() -= 5;
cout << StackData.top() << endl;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In this program, We used top option and this will return the reference to the next element.
- What is the output of this program?
#include <iostream>
#include <stack>
using namespace std;
int main ()
{
stack<int> StackData;
cout << (int) StackData.size();
for (int k =0; k < 5; k++)
{
StackData.push(k);
cout << " ";
cout << (int) StackData.size() << " ";
}
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
In this program, We declared myints and not initialized in first option, So it’s value is 0 and on another, We are pushing 5 values, So it’s size is 5.
- What is the output of this program?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
priority_queue<int> QueueData;
QueueData.push(25);
QueueData.push(75);
QueueData.push(45);
QueueData.push(55);
while (!QueueData.empty())
{
cout << " " << QueueData.top();
QueueData.pop();
}
cout << endl;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In this program, We used priority_queue and with that we are pushing and popping out the elements.
- In which context does the stack operates?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
A stack is a container where elements operate in a LIFO context, where elements are inserted (pushed) and removed (popped) from the end of the container.
- What is the output of this program?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
queue<int> QueueData;
QueueData.push(15);
QueueData.push(45);
QueueData.back() -= QueueData.front();
cout << QueueData.back() << endl;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We used the queue operation and performed the back operation. Because of that operation, We got the output as 30.