This chapter describes the array implementation of queues that use a special array slot, called the reserved slot, to distinguish between an empty and a full queue. Write the definition of the class and the definitions of the function members of this queue design. Also, write a program (in main.cpp) to test various operations on a queue. //Header file QueueAsArray #ifndef H_QueueAsArray #define H_QueueAsArray #include #include using namespace std; template class queueType { public: const queueType& operator=(const queueType&); // overload the assignment operator void initializeQueue(); int isEmptyQueue() const; int isFullQueue() const; Type front() const; Type back() const; void addQueue(Type queueElement); void deleteQueue(); queueType(int queueSize = 100); queueType(const queueType& otherQueue); // copy constructor ~queueType(); //destructor private: int maxQueueSize; int queueFront; int queueRear; Type *list; //pointer to array that holds queue elements }; //TODO: Write method definitions here #endif //Header file: queueADT.h #ifndef H_queueADT #define H_queueADT template class queueADT { public: virtual bool isEmptyQueue() const = 0; //Function to determine whether the queue is empty. //Postcondition: Returns true if the queue is empty, // otherwise returns false. virtual bool isFullQueue() const = 0; //Function to determine whether the queue is full. //Postcondition: Returns true if the queue is full, // otherwise returns false. virtual void initializeQueue() = 0; //Function to initialize the queue to an empty state. //Postcondition: The queue is empty. virtual Type front() const = 0; //Function to return the first element of the queue. //Precondition: The queue exists and is not empty. //Postcondition: If the queue is empty, the program // terminates; otherwise, the first // element of the queue is returned. virtual Type back() const = 0; //Function to return the last element of the queue. //Precondition: The queue exists and is not empty. //Postcondition: If the queue is empty, the program // terminates; otherwise, the last // element of the queue is returned. virtual void addQueue(const Type& queueElement) = 0; //Function to add queueElement to the queue. //Precondition: The queue exists and is not full. //Postcondition: The queue is changed and queueElement // is added to the queue. virtual void deleteQueue() = 0; //Function to remove the first element of the queue. //Precondition: The queue exists and is not empty. //Postcondition: The queue is changed and the first // element is removed from the queue. }; #endif
This chapter describes the array implementation of queues that use a special array slot, called the reserved slot, to distinguish between an empty and a full queue.
Write the definition of the class and the definitions of the function members of this queue design.
Also, write a program (in main.cpp) to test various operations on a queue.
//Header file QueueAsArray
#ifndef H_QueueAsArray
#define H_QueueAsArray
#include <iostream>
#include <cassert>
using namespace std;
template<class Type>
class queueType
{
public:
const queueType<Type>& operator=(const queueType<Type>&);
// overload the assignment operator
void initializeQueue();
int isEmptyQueue() const;
int isFullQueue() const;
Type front() const;
Type back() const;
void addQueue(Type queueElement);
void deleteQueue();
queueType(int queueSize = 100);
queueType(const queueType<Type>& otherQueue); // copy constructor
~queueType(); //destructor
private:
int maxQueueSize;
int queueFront;
int queueRear;
Type *list; //pointer to array that holds queue elements
};
//TODO: Write method definitions here
#endif
//Header file: queueADT.h
#ifndef H_queueADT
#define H_queueADT
template <class Type>
class queueADT
{
public:
virtual bool isEmptyQueue() const = 0;
//Function to determine whether the queue is empty.
//Postcondition: Returns true if the queue is empty,
// otherwise returns false.
virtual bool isFullQueue() const = 0;
//Function to determine whether the queue is full.
//Postcondition: Returns true if the queue is full,
// otherwise returns false.
virtual void initializeQueue() = 0;
//Function to initialize the queue to an empty state.
//Postcondition: The queue is empty.
virtual Type front() const = 0;
//Function to return the first element of the queue.
//Precondition: The queue exists and is not empty.
//Postcondition: If the queue is empty, the program
// terminates; otherwise, the first
// element of the queue is returned.
virtual Type back() const = 0;
//Function to return the last element of the queue.
//Precondition: The queue exists and is not empty.
//Postcondition: If the queue is empty, the program
// terminates; otherwise, the last
// element of the queue is returned.
virtual void addQueue(const Type& queueElement) = 0;
//Function to add queueElement to the queue.
//Precondition: The queue exists and is not full.
//Postcondition: The queue is changed and queueElement
// is added to the queue.
virtual void deleteQueue() = 0;
//Function to remove the first element of the queue.
//Precondition: The queue exists and is not empty.
//Postcondition: The queue is changed and the first
// element is removed from the queue.
};
#endif
Step by step
Solved in 3 steps with 1 images