Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.224.55.193
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/grpatillo/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/grpatillo/queuearray.cpp
/*      File Name:      queuearray.cpp
        Author:         R.P. Patillo
        Instructor:     Dr. Ames
        Due Date:       Oct. 23, 2008
        Complilation:   g++ queueclient.cpp -o queueclient.out
        Execution:      ./queueclient.out
*/

// 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 - returns a copy of the item located in the Nth position of a stack
//----------------------------------------------------------------------------
// Returns:   copy of Nth item
//---------------------------------------------------------------------------

template<class ItemType>
void QueueType<ItemType>::CopyNth(int N, ItemType& copyitem)
{
    copyitem = items[(front + N) % MAXQUEUE];	// copyitem wraps around MAXQUEUE back to the items[0]
}

Stv3n404 - 2023