i'm typing my code for my assignment and i'm required to create 2 queues in the simulation file which are the customer queue and server queue which are DYNAMIC QUEUE as required in the question
i confused that whether i need to create a new queuetype in the simulation header file or i can just use the same header file but i worry that the value between 2 queues will crashed (something like this) if i use the same header file for 2 queue
Question: Can I use the same queue ADT file for 2 different queues? this is my code for the queue ADT header file
#ifndef H_queueAsLinkedList
#define H_queueAsLinkedList
#include <iostream>
#include <cassert>
#include "queueADT_2.h"
using namespace std;
//Definition of the node
template <class T>
struct nodeType
{
T info;
nodeType<T> *link;
};
template <class T>
class queueAsLinkedList: public queueADT<T>
{
public:
const queueAsLinkedList<T>& operator=(const queueAsLinkedList<T>&);
//Overload the assignment operator.
bool isEmpty() const;
//Function to determine whether the queue is empty.
//Postcondition: Returns true if the queue is empty,
// otherwise returns false.
bool isFull() const;
//Function to determine whether the queue is full.
//Postcondition: Returns true if the queue is full,
// otherwise returns false.
void initializeQueue();
//Function to initialize the queue to an empty state.
//Postcondition: queueFront = nullptr; queueRear = nullptr
T qFront() const;
//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.
T qRear() const;
//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.
void enQueue(const T& queueElement);
//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.
void deQueue();
//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
// yelement is removed from the queue.
queueAsLinkedList();
//Default constructor
queueAsLinkedList(const queueAsLinkedList<T>& );
//Copy constructor
~queueAsLinkedList();
//Destructor
private:
nodeType<T> *queueFront; //pointer to the front of the queue
nodeType<T> *queueRear; //pointer to the rear of the queue
};
//********************implementation**************************
template <class T>
bool queueAsLinkedList<T>::isEmpty() const
{
return (queueFront == nullptr);
} //end isEmptyQueue
template <class T>
bool queueAsLinkedList<T>::isFull() const
{
return false;
} //end isFullQueue
template <class T>
void queueAsLinkedList<T>::initializeQueue()
{
nodeType<T> *temp;
while (queueFront!= nullptr) //while there are elements
//left in the queue
{
temp = queueFront; //set temp to point to the current node
queueFront = queueFront->link; //advance first to the next node
delete temp; //deallocate memory occupied by temp
}
queueRear = nullptr; //set rear to nullptr
} //end initializeQueue
template <class T>
void queueAsLinkedList<T>::enQueue(const T& newElement)
{
nodeType<T> *newNode;
newNode = new nodeType<T>; //create the node
newNode->info = newElement; //store the info
newNode->link = nullptr; //initialize the link
//field to nullptr
if (queueFront == nullptr) //if initially the queue is empty
{
queueFront = newNode;
queueRear = newNode;
}
else //add newNode at the end
{
queueRear->link = newNode;
queueRear = queueRear->link;
}
}//end enQueue
template <class T>
void queueAsLinkedList<T>::deQueue()
{
nodeType<T> *temp;
if (!isEmpty())
{
temp = queueFront; //make temp point to the first node
queueFront = queueFront->link; //advance queueFront
delete temp; //delete the first node
if (queueFront == nullptr) //if after deletion the queue is empty
queueRear = nullptr; //set queueRear to nullptr
}
else
cout << "Cannot remove from an empty queue" << endl;
}//end deQueue
template <class T>
T queueAsLinkedList<T>::qFront() const
{
assert(queueFront != nullptr);
return queueFront->info;
} //end front
template <class T>
T queueAsLinkedList<T>::qRear() const
{
assert(queueRear!= nullptr);
return queueRear->info;
} //end back
template <class T>
queueAsLinkedList<T>::queueAsLinkedList()
{
queueFront = nullptr; //set front to nullptr
queueRear = nullptr; //set rear to nullptr
} //end default constructor
template <class T>
queueAsLinkedList<T>::~queueAsLinkedList()
{
initializeQueue();
}// end Destructor
template <class T>
const queueAsLinkedList<T>& queueAsLinkedList<T>::operator=
(const queueAsLinkedList<T>& otherQueue)
{
cout << "Write the definition of the function "
<< "to overload the assignment operator." << endl;
} //end assignment operator
template <class T>
queueAsLinkedList<T>::queueAsLinkedList(const queueAsLinkedList<T>& otherQueue)
{
cout << "Write the definition of the copy constructor."
<< endl;
} //end copy constructor
#endif
sorry for my bad English, i can explain again if my description is confusing