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
Asked Dec 10, 2019
4 views

Please help with the follow question in C++

4) Consider the following Queue class that uses linked list to constract a Queae
class Node;
typedef Node NodePtr;
class Node
public:
int number;
NodePtr next;
Node({number =0; next NULL;}
Node(int n){number=n; next-NULL;}
11-
class Queue
private:
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 size
Queue (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 saccessfal
int dequeue (int& item); // removes an item from the Queue. Returns-1 if operation is not succesfist
bool empty0;
bool full();
Il checks if the Queue is empty
Il checks if the Queue is full
Note: Please answer the question on the next page
help_outline

Image Transcriptionclose

4) Consider the following Queue class that uses linked list to constract a Queae class Node; typedef Node NodePtr; class Node public: int number; NodePtr next; Node({number =0; next NULL;} Node(int n){number=n; next-NULL;} 11- class Queue private: 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 size Queue (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 saccessfal int dequeue (int& item); // removes an item from the Queue. Returns-1 if operation is not succesfist bool empty0; bool full(); Il checks if the Queue is empty Il checks if the Queue is full Note: Please answer the question on the next page

fullscreen
check_circle

Expert Answer

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:

help_outline

Image Transcriptionclose

/*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;

fullscreen
Step 2

Screenshot of the code #...

help_outline

Image Transcriptionclose

/ *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() // fullSize; return currSize ==

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

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

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Write a function MaxMagnitude() with two integer input parameters that returns the largest magnitude...

A: Below is the approach and the C++ program in which a function is defined with two integer parameters...

question_answer

Q: Did I correctly perform the SQL query below (photo attached): A query that contains the GROUP BY cla...

A: Given query:SELECT COUNT(PROF_NUM),DEPARTMENT_ID FROM COURSE GROUP BY DEPARTMENT_ID HAVING COUNT(PRO...

question_answer

Q: What is abstraction in c++?

A: Abstraction:The word abstraction means to display the essential information and hiding the details o...

question_answer

Q: Python-Coding-WHAT COLOUR SQUARE  PART 1 - Positions on a chess board are identified by a letter and...

A: Following is the python program which takes as input from user the position of chessboard. Check usi...

question_answer

Q: What is pseudo code?

A: Pseudocode is used in algorithm and programming based fields to outlines or represents the implement...

question_answer

Q: What is member function? Clarify with help of example?

A: Class:In C++, the class is the most important part of OOPS concept. Class is a programmer-defined da...

question_answer

Q: How would I be able to invoke all of my methods in an array if they do not have the same method name...

A: All Java programs for the given criteria is as follows,File name: “Person.java”public class Person{ ...

question_answer

Q: What is the output of the following code fragment? (beta is of type int.)   beta = 5; do {     s...

A: A given C++ program is,//Declare header file#include <iostream>//Declare namespaceusing namesp...

question_answer

Q: With separate domains, stricter resource control and administrative permissions are more difficult. ...

A: Stricter resource control and administrative permissionsStricter resource control and administrative...