//queue.h
#include<iostream>
using namespace std;
class Queue{
private:
double *arr;
int front,rear,capacity;
public:
Queue(int size){
capacity=size;
front=-1;
rear =-1;
arr = new
double[capacity];
}
~Queue(){
front=-1;
rear=-1;
capacity=0;
delete(arr);
}
bool isEmpty(){
return
front==-1;
}
bool isFull(){
return
(rear+1)%capacity==front;
}
void makeEmpty(){
front=-1;
rear=-1;
}
void enqueue(double data){
rear++;
rear%=capacity;
arr[rear]=data;
if(front==-1)front=rear;
}
void dequeue(double
&item){
item =
arr[front];
if(front==rear)
front=rear=-1;
else{
front++;
front%=capacity;}
}
void showQueue(){
int i =
front;
while(i!=rear){
cout<<arr[i]<<" ";
i++;
i%=capacity;
}
cout<<arr[rear]<<" ";
cout<<"\n\n";
}
};
//main.cpp
#include "queue.h"
void showMenu(){
cout<<"\nE- Enqueue\nD- Dequeue\nS- Show
Queue\nQ- Quit\n";
}
int main(){
Queue queue(5);
char choice;
double data;
do{
showMenu();
cout<<"Enter your choice :
";
cin>>choice;
switch(choice){
case'e':
case'E':{
if(queue.isFull()){
cout<<"Queue is
full\n";
}
else{
cout<<"Enter an item : ";
cin>>data;
queue.enqueue(data);
}
break;
}
case'd':
case'D':{
if(queue.isEmpty()){
cout<<"Queue is
empty\n\n";
}
else{
queue.dequeue(data);
cout<<"item :
"<<data<<"\n\n";
}
break;
}
case's':
case'S':{
queue.showQueue();
cout<<"\n";
break;
}
case'q':
case'Q':{
cout<<"Thank you!\n";
break;
}
default:{
cout<<"Invalid choice\n\n";
break;
}
}
}while(choice!='q'||choice!='Q');
return 0;
}
//sample output
Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds value...
Step 4 Develop a class with only a main method in it: public class QueueDemo { public static void main(String[ ] args) { /* Inside of this main method do the following: Create a reference to a QueueInterface<String> called myQueue and have it refer to a new object of the ImprovedQueue<String> class Call the enqueue method on myQueue passing the String value of “A” Call the enqueue method on myQueue passing the String value of “B” Call the...
use intellij idea main java Step 4 Develop a class with only a main method in it: public class QueueDemot public static void main(String[] args) { Inside of this main method do the following: Create a reference to a Queue Interface<String> called myQueue and have it refer to a new object of the ImprovedQueue<String> class Call the enqueue method on myQueue passing the String value of "A" Call the enqueue method on myQueue passing the String value of "B" Call...
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....
Using the below files, Write a program that reads a document containing endnotes indicated in this manner, collects them in a queue, and prints them on the screen. For this lab, you will create a text file called sample.txt and put the following paragraph in it. This part is the beginning. {This part is the footnote.} This part is the end. /* Queue.h contains the declaration of class Queue. Basic operations: Constructor: Constructs an empty queue empty: Checks if a...
lab 11 Do not change main.cpp, i need c++ code for queue.h and queue.cpp Given the complete main() function, partial queue class header queue.h, and queue.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor enqueue() dequeue() You may elect to create the following helper functions: isFull() isEmpty() A description of these ADT operations are available in this Zybook and in the textbook's chapter 17. Example: If the input is: 3 Led Zepplin...
You are going to create a Queue. (alternately you can create a list and simply implement enqueue and dequeue functions in the List – that will technically make it a queue). You will fill the first list with numbers consecutively numbered from 2 to n where n is entered by the user (we will call this Q1). When creating your Queue object use the correct function names for enqueue and dequeue functions. Again – sorry, cannot use an Javascript array...
i was able to make sense on the others but this two i need help Name: ImprovedQueue<T> Access Modifier: public Implements: QueueInterface<T> Instance variables Name: front Access modifier: private Data type: QueueNode<T> Constructors: Name: ImprovedQueue Access modifier: public Parameters: none (default constructor) Task: sets the value of front to null Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Task: returns true if the front is equal to null; otherwise return false Name: dequeue Access modifier: public Parameters:...
QUEUEBOX: Using an Array of initial size of five (5) for storage, start with the following generic class declaration for QueueBox: public class QueueBox<E> { private E[] elements = (ED))( new Object[5]); private int front_idx = 0; private int rear_idx = 0; private int count = 0; Hint: use the count variable to keep track of how many elements are in the queue (increment count when enqueing and decrement when dequeing). Makes it a lot easier to determine if the...
Write In C program Bart Simpson is a pharmacist and likes to handle his customers' request as soon as possible. The customer who comes first get their prescription filled first. Write a menu-based program that helps Bart Simpson fill prescription order queue shown here: Name Angie Bertha Charlie Medication Lipitor Nexium Epogen The prescription queue is empty when the program starts. The menu should be as follows. Your choice is managed by switch statement and each choice requires a separated...
help finish Queue, don't think I have the right thing. # 1. After studying the Stack class and testStack() functions in stack.py # complete the Queue class below (and test it with the testQueue function) # # 2. Afer studying and testing the Circle class in circle.py, # complete the Rectangle class below (and test it with the testRectangle function) # # # 3. SUBMIT THIS ONE FILE, with your updates, TO ICON. # # # NOTE: you may certainly...