Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ template class named \"dequeue.template\" based on the following hea

ID: 3676092 • Letter: W

Question

Write a C++ template class named "dequeue.template" based on the following header declarations. The comments about the declarations give you instructions on what to implement in the implementation file.

// dequeue.h

#ifndef _DEQUE_H_

#define _DEQUE_H_

#include <iostream>

#include <cstdlib>

using namespace std;

template <class T>

class dequeue

{

public:

typedef size_t size_type;

static const size_type CAPACITY = 10;

//postcondition: empty deque has been created

dequeue();

//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 front 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: whether 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 <class T>

friend bool operator == (const dequeue<T>& dq1, const dequeue<T>& dq2);

// postcondition: dq has been display from front to rear on out

template <class T>

friend ostream& operator<< (ostream& out, const dequeue<T>& 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;

// postcondition: returned previous index in array

size_type prev_index (size_type i) const;

};

#include "dequeue.template"

#endif

Explanation / Answer

#include #include using namespace std; // Node Declaration struct Node { int value; node *next; node *prev; }*head, *tail; class dequeue { public: int top1, top2; void insert(); // inserts an elements in queue void del(); //delets an element in queue void display(); // displays an element in queue dqueue() { top1 = 0; top2 = 0; head = NULL; tail = NULL; } }; void main() { int choice; dequeue dl; while (1) { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote