I'm not really sure how to go about implementing these functions in my queue, any help is greatly appreciated!
Edit: I just realized, I also have no idea where to start for the copy constructor
#include <iostream>
using namespace std;
template<class ItemType>
class Queue
{
private:
int front;
int rear;
int maxQue;
ItemType* items;
public:
Queue();
Queue(const Queue<ItemType> &x);
void MakeEmpty();
bool IsEmpty();
bool IsFull();
int length();
void Print();
void Enqueue(ItemType x);
void Dequeue(ItemType &x);
~Queue();
};
template<class ItemType>
Queue<ItemType>::Queue()
{
maxQue = 501;
front = maxQue - 1;
rear = maxQue - 1;
items = new ItemType[maxQue];
}
template<class ItemType>
Queue<ItemType>::~Queue()
{
delete [] items;
}
template<class ItemType>
void Queue<ItemType>::MakeEmpty()
{
front = maxQue - 1;
rear = maxQue - 1;
}
template<class ItemType>
bool Queue<ItemType>::IsEmpty()
{
return (rear == front);
}
template<class ItemType>
bool Queue<ItemType>::IsFull()
{
return ((rear + 1) % maxQue == front);
}
template<class ItemType>
void Queue<ItemType>::Enqueue(ItemType newItem)
{
if (IsFull())
cout << "Full" << endl;
else
{
rear = (rear + 1) % maxQue;
items[rear] = newItem;
}
}
template<class ItemType>
void Queue<ItemType>::Dequeue(ItemType& item)
{
if (IsEmpty())
cout << "Empty" << endl;
else
{
front = (front + 1) % maxQue;
item = items[front];
}
}
template<class ItemType>
int Queue<ItemType>::length()
{
}
template<class ItemType>
void Queue<ItemType>::Print()
{
}
int main()
{
Queue<int>IntQueue;
int x;
IntQueue.MakeEmpty();
IntQueue.Dequeue(x);
IntQueue.Enqueue(1);
IntQueue.Enqueue(2);
IntQueue.Enqueue(3);
IntQueue.Enqueue(4);
//cout << "int length 3 = " << IntQueue.length() << endl;
IntQueue.Dequeue(x);
//cout << "int length 4 = " << IntQueue.length() << endl;
cout << "The int queue contains: " << endl;
IntQueue.Print();
if(IntQueue.IsFull() == false)
cout << "The int queue is not full !" << endl;
Queue<float>FloatQueue;
float y;
FloatQueue.MakeEmpty();
FloatQueue.Dequeue(y);
FloatQueue.Enqueue(7.1);
//cout << "float length 3 = " << FloatQueue.length() << endl;
FloatQueue.Enqueue(2.3);
//cout << "float length 4 = " << FloatQueue.length() << endl;
FloatQueue.Enqueue(3.1);
FloatQueue.Dequeue(y);
cout << "The float queue contains: " << endl;
// FloatQueue.Print();
//Queue<float> FloatQueue2 = FloatQueue;
cout << "The float queue 2 contains: " << endl;
//FloatQueue2.Print();
FloatQueue.MakeEmpty();
cout << "The float queue 3 contains: " << endl;
//FloatQueue2.Print();
system("PAUSE");
return 0;
}