MediaTek interview question

what is dequeue , how to implement it

Interview Answer

Anonymous

19 Mar 2025

✅ Supports insertion/deletion at both ends in O(1) time. ✅ Provides random access like a vector (via indexing). ✅ Efficient for both stack and queue operations. ✅ Implements dynamic resizing like a vector but allows growth in both directions. deque Syntax in C++ The C++ Standard Library (#include ) provides the deque container class. cpp Copy Edit #include #include using namespace std; int main() { deque dq; // Inserting elements dq.push_back(10); // Insert at back dq.push_front(5); // Insert at front // Displaying elements cout << "Deque elements: "; for (int x : dq) { cout << x << " "; } // Removing elements dq.pop_back(); // Remove from back dq.pop_front(); // Remove from front // Checking size cout << "\nSize of deque: " << dq.size() << endl; return 0; }