Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add an element to the queue.
DSA C++
std::queue<int> q; q.[1](10);
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() instead of push() to add elements.
Trying to access front() to add elements.
✗ Incorrect
The push() function adds an element to the back of the queue.
2fill in blank
mediumComplete the code to remove the front element from the queue.
DSA C++
std::queue<int> q; q.push(5); q.push(7); q.[1]();
Attempts:
3 left
💡 Hint
Common Mistakes
Using push() instead of pop() to remove elements.
Trying to use front() to remove elements.
✗ Incorrect
The pop() function removes the front element from the queue.
3fill in blank
hardFix the error in accessing the front element of the queue.
DSA C++
std::queue<int> q; q.push(3); int x = q.[1]();
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() which removes the element instead of accessing it.
Using push() which adds elements.
✗ Incorrect
The front() function returns the front element without removing it.
4fill in blank
hardFill both blanks to check if the queue is empty and print a message.
DSA C++
if (q.[1]()) { std::cout << "Queue is [2]" << std::endl; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using size() instead of empty() to check emptiness.
Printing 'full' instead of 'empty' when queue is empty.
✗ Incorrect
The empty() function checks if the queue has no elements. If true, print 'empty'.
5fill in blank
hardFill all three blanks to create a queue, add elements, and print the front element.
DSA C++
std::queue<int> [1]; [1].[2](20); std::cout << [1].[3]() << std::endl;
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() instead of front() to access element.
Using inconsistent variable names.
✗ Incorrect
Create queue named q, push 20, then print front element using front().
