Create a deque class in c using an array as the main data st
Create a deque class (in c++) using an array as the main data structure. The class should have the functions pop_front(), pop_back(), push_front(), push_back(). Create other data members as required.
Solution
Answer:
#include <iostream>
#include <deque>
using namespace std;
int main() {
deque<int> deq;
for (int i=0; i<5; ++i) {
deq.push_back(i);
}
for (int i=0; i<(signed)deq.size(); ++i) cout << deq.at(i);
cout << endl;
for (int i=0; i<3; ++i) {
deq.push_front(8);
}
for (int i=0; i<(signed)deq.size(); ++i) cout << deq.at(i);
cout << endl;
deq.pop_front();
deq.pop_back();
for (int i=0; i<(signed)deq.size(); ++i) cout << deq.at(i);
cout << endl;
return 0;
}
