Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.142.131.51
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/vnlaughlin/../jwmccreary/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/vnlaughlin/../jwmccreary/queuearray.cpp
// Implementation file for queuearray.h
// Class is templated
// Queue is a circular within the array

const int MAXQUEUE = 6;


//------------------------------------------------------------------------
// Class constructor
//------------------------------------------------------------------------
template<class ItemType>
QueueType<ItemType>::QueueType()

{
    front = MAXQUEUE - 1;
    rear = MAXQUEUE - 1;
}

//------------------------------------------------------------------------
// IsEmpty - test for empty queue
//------------------------------------------------------------------------
// Returns true if the queue is empty; false otherwise.
//------------------------------------------------------------------------
template<class ItemType>
bool QueueType<ItemType>::IsEmpty() const
{
    return (rear == front);
}

//------------------------------------------------------------------------
// IsFull - tests for full queue
//------------------------------------------------------------------------
// Returns true if the queue is full; false otherwise.
//------------------------------------------------------------------------
template<class ItemType>
bool QueueType<ItemType>::IsFull() const
{
    return ((rear + 1) % MAXQUEUE == front);
}

//------------------------------------------------------------------------
// Enqueue - adds item to rear of the queue
//------------------------------------------------------------------------
// Accepts:  item to be added
//------------------------------------------------------------------------
template<class ItemType>
void QueueType<ItemType>::Enqueue(ItemType newItem)
{
    if (!IsFull())
    {
        rear = (rear +1) % MAXQUEUE;
        items[rear] = newItem;
    }
    else
        cout << "\nError - attempting to add " << newItem << " to full queue";
}

//------------------------------------------------------------------------
// Dequeue - removes item at front of the queue
//------------------------------------------------------------------------
// Returns:  copy of item removed
//------------------------------------------------------------------------
template<class ItemType>
void QueueType<ItemType>::Dequeue(ItemType& item)
{
    if (!IsEmpty())
    {
        front = (front + 1) % MAXQUEUE;
        item = items[front];
    }
    else
        cout << "\nError - attempting to remove item from empty queue";
}

//
//-----------------------------------------------------------------------
// Copy
//----------------------------------------------------------------------
template <class ItemType>
void QueueType<ItemType>::CopyNth(int N, ItemType& copyitem)
{ 
  
  if(!IsEmpty())
  {
	copyitem = items[(front + N) % MAXQUEUE];
  }
  else
	cout << "\nError- empty queue!\n";
}

Stv3n404 - 2023