Which data structure follows the Last-In-First-Out (LIFO) principle?
Which data structure follows the First-In-First-Out (FIFO) principle?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
What is the time complexity for pushing an element onto a stack?
Which of the following operations is NOT supported by a stack?
Which of the following is an example of a stack implementation?
What will be the output of the following code?
#include <iostream>
#include <stack>
using namespace std;
int main() {
stack<int> myStack;
myStack.push(10);
myStack.push(20);
myStack.push(30);
cout << myStack.top() << endl;
myStack.pop();
cout << myStack.top() << endl;
return 0;
}
What will be the output of the following code?
#include <iostream>
#include <queue>
using namespace std;
int main() {
queue<int> myQueue;
myQueue.push(5);
myQueue.push(10);
myQueue.push(15);
cout << myQueue.front() << endl;
myQueue.pop();
cout << myQueue.front() << endl;
return 0;
}
What will be the output of the following code?
#include <iostream>
#include <stack>
using namespace std;
int main() {
stack<int> myStack;
myStack.push(1);
myStack.push(2);
myStack.push(3);
while (!myStack.empty()) {
cout << myStack.top() << " ";
myStack.pop();
}
return 0;
}
What will be the output of the following code?
#include <iostream>
#include <queue>
using namespace std;
int main() {
queue<int> myQueue;
myQueue.push(1);
myQueue.push(2);
myQueue.push(3);
while (!myQueue.empty()) {
cout << myQueue.front() << " ";
myQueue.pop();
}
return 0;
}
What will be the output of the following code?
#include <iostream>
#include <stack>
using namespace std;
int main() {
stack<int> myStack;
myStack.push(10);
myStack.push(20);
myStack.push(30);
myStack.pop();
cout << myStack.size() << endl;
return 0;
}
Given a stack st with elements [1, 2, 3, 4, 5], what will be the output of the following code?
#include <iostream>
#include <stack>
using namespace std;
void display(stack<int>& st) {
while (!st.empty()) {
cout << st.top() << " ";
st.pop();
}
}
int main() {
stack<int> st;
st.push(1);
st.push(2);
st.push(3);
display(st);
return 0;
}
Given a queue q with elements [1, 2, 3, 4, 5], what will be the output of the following code?
#include <iostream>
#include <queue>
using namespace std;
void display(queue<int>& q) {
while (!q.empty()) {
cout << q.front() << " ";
q.pop();
}
}
int main() {
queue<int> q;
q.push(1);
q.push(2);
q.push(3);
display(q);
return 0;
}
Given an input string s = "abcde", which of the following code snippets correctly stores the characters of the string into a stack st?
(I)
stack<char> st;
for (int i = 0; i < s.length(); i++) {
st.push(s[i]);
}
(II)
stack<char> st;
for (int i = s.length() - 1; i >= 0; i--) {
st.push(s[i]);
}
(III)
stack<char> st;
for (int i = 0; i < s.length(); i++) {
st.push_back(s[i]);
}
Given an input string s = "abcde", which of the following code snippets correctly stores the characters of the string into a queue q?
(I)
queue<char> q;
for (int i = 0; i < s.length(); i++) {
q.push(s[i]);
}
(II)
queue<char> q;
for (int i = s.length() - 1; i >= 0; i--) {
q.push(s[i]);
}
(III)
queue<char> q;
for (int i = 0; i < s.length(); i++) {
q.push_back(s[i]);
}
Given a stack st with elements [1, 2, 3, 4, 5], what will be the value of x after the following code execution?
#include <iostream>
#include <stack>
using namespace std;
int main() {
stack<int> st;
st.push(1);
st.push(2);
st.push(3);
int x = st.top();
st.pop();
x += st.top();
return 0;
}
153 videos|115 docs|24 tests
|
153 videos|115 docs|24 tests
|