Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Construct a C++ implementation of a static queue class.. Write test program to test every member functions implemented in the class. This is the header

Construct a C++ implementation of a static queue class.. Write test program to test every member functions implemented in the class. This is the header file.

#ifndef _DEQUE_H_ #define _DEQUE_H_

#include #include

template class deque { public: typedef std::size_t size_type; static const size_type CAPACITY = 10; //postcondition: empty deque has been created deque(); //precondition: deque is not empty // postcondition: reference to element at front of deque // has been returned T& front(); // precondition: deque is not empty // postcondition: copy of element at front of deque // has been returned T front() const; // precondition: deque is not empty // postcondition: reference to element at the back of deque // has been returned T& back(); // precondition: deque is not empty // postcondition: copy of element at back of deque // has been returned T back() const; // precondition: deque is not full // postcondition: entry has been inserted at the front // of the deque void push_front (const T& entry); // precondition: deque is not full // postcondition: entry has been inserted at the back // of the deque void push_back (const T& entry); // precondition: deque is not empty // postcondition: element at front of deque has been removed void pop_front(); // precondition: deque is not empty // postcondition: element at back of deque has been removed void pop_back(); // postcondition: number of elements in deque has been returned size_type size() const; // postcondition: wheth er deque is empty has been returned bool empty() const; // postcondition: whether deque is full has been returned bool full() const; // postcondition: returned whether 2 deques are equal - equal is defined // as the deques have the same number of elements & // corresponding elements are equal template friend bool operator == (const deque& dq1, const deque& dq2);

// postcondition: dq has been displayed from front to rear template friend std::ostream& operator<< (std::ostream& out, const deque& dq);

private: T data[CAPACITY]; // Circular array size_type first; // Index of item at front of the queue size_type last; // Index of item at rear of the queue size_type count; // Total number of items in the queue

// postcondition: returned next index in array size_type next_index(size_type i) const {return (i+1)% CAPACITY; } // postcondition: returned previous index in array size_type prev_index (size_type i) const {return (i+CAPACITY-1)% CAPACITY;} };

#include "deque.template"

#endif

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

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

=+b. What was the amount of gross profit?

Answered: 1 week ago