Question
Please fix the deque.template file so that the test program runs correctly. My program: deque.template //File: deque.template //This program is a static implementation of a
Please fix the deque.template file so that the test program runs correctly.
My program:
deque.template
//File: deque.template //This program is a static implementation of a deque
#include
using namespace std;
//postcondition: empty deque has been created template
// postcondition: newly created deque is a copy of dq template
return return first->data(); } //precondition: deque is not empty //postcondition: copy of element at front of deque //has been returned template
} //postcondition: number of elements in deque has been returned template
deque.h
#ifndef _DEQUE_H_ #define _DEQUE_H_ #include#include #include template
class deque { public: deque(); //postcondition: empty deque has been created T& front(); // precondition: deque is not empty // postcondition: reference to element at front of deque // has been returned T front() const; // precondition: deque is not empty // postcondition: copy of element at front of deque // has been returned T& back(); // precondition: deque is not empty // returned: reference to element at front of deque T back() const; // precondition: deque is not empty // returned: copy of element at back of deque void push_front (const T& entry); // postcondition: entry has been inserted at the front // of the deque void push_back (const T& entry); // postcondition: entry has been inserted at the back // of the deque void pop_front(); // precondition: deque is not empty // postcondition: element at front of deque has been removed void pop_back(); // precondition: deque is not empty // postcondition: element at back of deque has been removed size_t size() const; // postcondition: number of elements in deque has been returned bool empty() const; // returned: whether deque is empty template friend bool operator == (const deque& dq1, const deque& dq2); // returned: whether 2 deques are equal - equal is defined // as the deques have the same number of elements & // corresponding elements are equal template friend std::ostream& operator<< (std::ostream& out, const deque& dq); // postcondition: dq has been display from front to rear on out private: std::list l; }; #include "deque.template" #endif
test_deque.cpp
#include#include "deque.h" using namespace std; int main(int argc, char **argv) { deque dq; cout << dq << endl; for (int i = 0; i < 10; i++) dq.push_front (i); cout << dq << endl; dq.pop_back(); cout << dq << endl; dq.push_front (24); cout << dq << endl; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started