# 4) Consider the following Queue class that uses linked list to constract a Queaeclass Node;typedef Node NodePtr;class Nodepublic:int number;NodePtr next;Node({number =0; next NULL;}Node(int n){number=n; next-NULL;}11-class Queueprivate:NodePtr top;int currSize;const int fullSize;public:I/ initializes the Queue to an empty Queue (fixed size of 5)Queue ()fullSize = 5;currsize =0;top = NULL;I/ initializes the Queue to an empty Queue and specific maximum sizeQueue (int maxSize)fullSize = maxSize;currsize =0;top NULL;Palke?int enqueue (int item); // places an item into the Queue. Returns-1 if operation is soE saccessfalint dequeue (int& item); // removes an item from the Queue. Returns-1 if operation is not succesfistbool empty0;bool full();Il checks if the Queue is emptyIl checks if the Queue is fullNote: Please answer the question on the next page

Question
4 views

check_circle

Step 1

A Queue is constructed as follows,

/*Define the method that places an item into the Queue

and returns -1 if operation is not successful*/

int Queue::enqueue (int item)

{

if(full())

return -1;

NodePtr n = new Node(item);

if(empty())

top = n;

else

{

NodePtr last = top;

while(last->next != NULL)

last = last-> next;

last->next = n;

}

currSize++;

return 1;

}

/*Define the method dequeue() that removes an item from

the Queue and returns -1 if operation is not successful*/

int Queue::dequeue (int& item)

{

if(empty())

return -1; //not success

item = top->number;

NodePtr temp = top;

top = top->next;

delete top;

currSize--;

return 1;//success

}

//Define the method empty() that checks if the Queue is empty

bool Queue::empty()

{

return currSize == 0;

}

//Define the method full() that checks if the Queue is full

bool Queue::full() //

{

return currSize == fullSize;

}

Screenshot of the code #1:

Step 2

Screenshot of the code #...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in