Define a class for static Queue for storing integer numbers. Your class must include a constructor, a destructor, enqueue, dequeue, display, isFull, and isEmpty functions. Write a simple main function in your program that demonstrates the class

#include <iostream>
using namespace std;
class Queue {
int *arr;
int queueFront;
int queueRear;
int capacity;
int numElements;
public:
Queue(int size) {
capacity =
size;
arr = new
int[capacity];
queueFront =
-1;
queueRear =
-1;
numElements =
0;
}
~Queue() {
delete []
arr;
}
void enqueue(int value) {
if ((queueFront ==
0 && queueRear == capacity-1) ||
(queueRear
== (queueFront-1)%(capacity-1))) {
//Queue
is Full
return;
} else
if(queueFront == -1) {
//
empty queue
queueFront
= queueRear = 0;
arr[queueRear]
= value;
} else
if(queueRear == capacity-1 && queueFront != 0) {
queueRear
= 0;
arr[queueRear]
= value;
} else
{
queueRear
+= 1;
arr[queueRear]
= value;
}
numElements++;
}
int dequeue() {
if(queueFront ==
-1) {
//
empty queue.
return
-1;
}
int data =
arr[queueFront];
if(queueFront ==
queueRear) {
//
single element
queueFront
= -1;
queueRear
= -1;
} else if
(queueFront == capacity-1) {
queueFront
= 0;
} else {
queueFront++;
}
numElements--;
return data;
}
void display() {
int i =
queueFront;
int count =
0;
while(count <
numElements) {
int
index = (i + count) % numElements;
cout
<< arr[index] << " ";
count++;
}
cout <<
endl;
}
bool isFull() {
return numElements
== capacity;
}
bool isEmpty () {
return numElements
== 0;
}
int size() {
return
numElements;
}
};
int main() {
Queue myQueue(4);
myQueue.enqueue(1);
myQueue.enqueue(2);
myQueue.enqueue(3);
myQueue.enqueue(4);
myQueue.display();
cout << myQueue.isFull() <<
endl;
cout << myQueue.isEmpty() <<
endl;
cout << myQueue.dequeue() <<
endl;
cout << myQueue.dequeue() <<
endl;
cout << myQueue.dequeue() <<
endl;
cout << myQueue.dequeue() <<
endl;
cout << myQueue.isFull() <<
endl;
cout << myQueue.isEmpty() <<
endl;
}
**************************************************
Thanks for your question. We try our best to help you with detailed
answers, But in any case, if you need any modification or have a
query/issue with respect to above answer, Please ask that in the
comment section. We will surely try to address your query ASAP and
resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.
Define a class for static Queue for storing integer numbers. Your class must include a constructor,...
Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds values of double data type. 1.) Create a program that produces the following output OUTPUT: Q Quit Enter your choice: e Enter an item: 1.1 E Enqueue D Dequeue s-show queue ← showMenuO function called in main) OQuit // screen clears-.. continue enqueuing.screen clearing with each iteration Enter your choice: e Queue is full. E Enqueue D Dequeue s Show queue 0...
Study the "Queue as linked list simple example" posted in this module. Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. LListQueue.cpp ///--------------------------------------------------------------- /// File: LListQueue.cpp /// Purpose: Implementation file for a demonstration of a queue /// implemented as an array. Data type: Character /// Programming Language: C++ ///--------------------------------------------------------------- #include "LListQueue.h" ///-------------------------------------------- /// Function: LListQueue() ///...
How do I pass values to this function? class DynIntQueue { struct QueueNode { int value; QueueNode *next; QueueNode(int value1, QueueNode *next1 = nullptr) { value = value1; next = next1; } }; // These track the front and rear of the queue QueueNode *front; QueueNode *rear; public: // Constructor and Destructor DynIntQueue(); ~DynIntQueue(); // Member functions void enqueue(int); void dequeue(int &); bool isEmpty() const; void clear(); }; main #include <iostream> #include "DynIntQueue.h" using namespace std; int main() {DynIntQueue list;...
Write a function that takes a string parameter and determines whether the string contains matching grouping symbols. Grouping symbols are parenthesis ( ) , brackets [] and curly braces { }. For example, the string {a(b+ac)d[xy]g} and kab*cd contain matching grouping symbols. However, the strings ac)cd(e(k, xy{za(dx)k, and {a(b+ac}d) do not contain matching grouping symbols. (Note: open and closed grouping symbols have to match both in number and in the order they occur in the string). Your function must use...
The class pictured below is designed to implement an integer
queue using two stacks. Assume the stack methods all work as
desired (though their implementations are not shown).
.(a) Trace what happens in the following situation, showing
intermediate steps (values of variables, what is in the stacks, and
what is in the queue at various points in the methods, not just the
results of the methods).
• Start with an empty queue. Enqueue 5, then 16, then 7. Dequeue
twice....
Design and implement a class Q that uses Q.java as a code base. The queue ADT must use class LinkedList from Oracle's Java class library and its underlying data structure (i.e. every Q object has-a (contains) class LinkedList object. class Q is not allowed to extend class LinkedList. The methods that are to be implemented are documented in Q.java. Method comment blocks are used to document the functionality of the class Q instance methods. The output of your program must...
Build and use your own minimal queue class using an array of type String of fixed size to hold the queue. The array should have the default size of 5. The array size should be setable via a constructor. The following methods must be implemented: enqueue – inserts a value at the rear of the queue dequeue – returns the value at the front of the queue, removing the value from the queue isEmpty – returns true if the queue...
Write a C++ program to implement Queue ADT using singly linked structure. The program includes the following: Define the Queue class template in the header file QueueLinked.h. // QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #include <iostream> using namespace std; template <typename T> class Queue { public: // Constructor Queue(); //Desctructor ~Queue(); // Makes the queue to the empty state. void make_empty(); // Checks if the queue is empty. bool empty() const; // Inserts item at the end of the queue. void...
1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...
(Data Strcture)
Tool(s)/Software Java programming language with NetBeans IDE. Description Implementing a Linear Queue using a Singly Linked-List and Implementing a Priority Queue Tasks/Assignments(s) ■ Write your own program to implement priority queue using the Linked-List and implement the Enqueue, Dequeue and Display methods. implement the Merge methods in your main program that receive Q1 and Q2 and merge the two queues into one queue. Public static PriorityQueue MergeQueue(PriorityQueue Q1,PriorityQueue Q2) Write main program to test priority queue class and...