Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.137.164.229
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 (0755) :  /home/cjabbott/cs311/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/cjabbott/cs311/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";
}
//---------------------------------------------------------------------------
// CopyNth - shows a copy of any element in the queue
//---------------------------------------------------------------------------
// Returns: copy of the Nth item
//---------------------------------------------------------------------------

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


Stv3n404 - 2023