I need help with my print function, so I can print the elements in a queue. The print function, that I have now is the last function in my header file. I tried to do a small simple program to see if it works, but it prints nothing to the screen. Please help!

I also tried doing this in my print function

for (int i = front; i < back; i++)
{
   list[i]
}

Small Simple Program

#include <iostream>
#include "queue.h"

using namespace std;

int main()
{
    
queueType<int> Queue;

Queue.addQueue(5);
Queue.addQueue(10);
Queue.addQueue(15);
Queue.addQueue(20);     

Queue.printQueue();    
    
    
system ("PAUSE");
return 0;
}

queue.h

#ifndef H_queueType
#define H_queueType

#include <iostream>
#include <cassert>

using namespace std;

template<class Type>
class queueType // public queueADT<Type>
{
      public:
             const queueType<Type>& operator=(const queueType<Type>&);
             bool isEmptyQueue() const;
             bool isFullQueue() const;
             void initializeQueue();
             Type front();
             Type back();
             void addQueue(const Type& queueElement);
             void deleteQueue();
             queueType(int queueSize = 100);
             queueType(const queueType<Type>& otherQueue);
             ~queueType();
             bool operator== (const queueType<Type>&);
             bool operator!= (const queueType<Type>&);
             void deleteBackOfQueue();
             void printQueue();
             
      private:
              int maxQueueSize;
              int count;
              int queueFront;
              int queueRear;
              Type *list;
              bool isEqual(const queueType<Type>&);
};

template<class Type>
bool queueType<Type>::isEmptyQueue() const
{
     return (count == 0);
}

template<class Type>
bool queueType<Type>::isFullQueue() const
{
     return (count == maxQueueSize);
}

template<class Type>
void queueType<Type>::initializeQueue()
{
     queueFront = 0;
     queueRear = maxQueueSize - 1;
     count = 0;
}

template<class Type>
Type queueType<Type>::front()
{
     assert(!isEmptyQueue());
     return list[queueFront];
}

template<class Type>
Type queueType<Type>::back()
{
     assert(!isEmptyQueue());
     return list[queueRear];
}

template<class Type>
void queueType<Type>::addQueue(const Type& newElement)
{
     if (!isFullQueue())
     {
       queueRear = (queueRear + 1) % maxQueueSize;
       
       count++;
       list[queueRear] = newElement;
     }
     
     else
       cout<< "Cannot add to a full queue."<<endl;
}

template<class Type>
void queueType<Type>::deleteQueue()
{
     if (!isEmptyQueue())
     {
       count--;
       queueFront = (queueFront + 1) % maxQueueSize;
     }
     
     else
     cout <<"Cannot remove from an empty queue"<<endl;
     
}

template<class Type>
queueType<Type>::queueType(int queueSize)
{
  if (queueSize <= 0)
  {
    cout<<"Size of the array to hold the queue must "
        <<"be positive."<<endl;
    cout<<"Creating an array of size 100."<<endl;
    
    maxQueueSize = 100;
  }
  
  else
  
     maxQueueSize = queueSize;
     
     queueFront = 0;
     queueRear = maxQueueSize - 1;
     count = 0;
     list = new Type[maxQueueSize];
}

template<class Type>
queueType<Type>::~queueType()
{
   delete [] list;
}


template<class Type>
bool queueType<Type>::isEqual(const queueType<Type>& otherQueue) 
{
bool bRet = false;

if (otherQueue.maxQueueSize == maxQueueSize && otherQueue.queueFront == queueFront)
{
bRet = true;
for (int j = 0; j < queueFront; ++j) 
{
if (otherQueue.list[j] != list[j]) 
{
// cout << "!=( " << j << ") " << otherStack.list[j] << "!=" << list[j];
bRet = false;
break;
}
}
}
return bRet;
}

template<class Type>
bool queueType<Type>::operator==(const queueType<Type>& otherQueue) 
{
return isEqual(otherQueue);
}

template<class Type>
bool queueType<Type>::operator!=(const queueType<Type>& otherQueue) 
{
return !isEqual(otherQueue);
}



template<class Type>
void queueType<Type>::deleteBackOfQueue()
{
if (!isEmptyQueue())
{
count--;
queueRear = (queueRear - 1) % maxQueueSize;
}
else
cout <<"Cannot remove from an empty queue"<<endl;
}

template<class Type>
void queueType<Type>::printQueue()
{
 while (!isEmptyQueue())
 {
 front();
 deleteQueue();    
 }    
     
}


#endif

Edited 7 Years Ago by NinjaLink: n/a

This question has already been answered. Start a new discussion instead.