Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++: The assignment is to create a dynamic implementation of a deque. This implementation uses the template linked list class from STL (#include ). These

C++: The assignment is to create a dynamic implementation of a deque. This implementation uses the template linked list class from STL (#include ).

These are the files needed for the implementation;

The header file: 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

The test file: 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

Students also viewed these Databases questions

Question

What is accrued revenue?

Answered: 1 week ago

Question

a. Describe the encounter. What made it intercultural?

Answered: 1 week ago