← Back to Data Structures & Algorithms
Question 530
Queue On A Deque
Queue On A Deque
Complete the Queue class built on from collections import deque: enqueue(item) adds at the back with append(), dequeue() removes and returns the front item with popleft(), is_empty() returns whether nothing is waiting, and size() returns how many items are waiting. A deque makes both ends O(1), which a plain list cannot do for its front. Do NOT write a main block or any top-level test code; the tests construct the class. Input: one line of space-separated words (possibly empty); the tests enqueue every word, print the size, dequeue the items one at a time printing each, and finally print whether the queue is empty.
Expected Output:
3 ann bob cat True
= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Data Structures & Algorithms
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.