
//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...
In Java, create a program implementing the functionalities of a standard queue in a class called Queue3503. You will test the functionalities of the Queue3503 class from the main() method of the Main class. In a queue, first inserted items are removed first and the last items are removed at the end (imagine a line to buy tickets at a ticket counter). Do NOT change your class name from "Main". The Main class should come first in your code. Your filename should be "Main.java". The Queue3503 class will contain:...
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() ///...
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...
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...
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...
java Create a Queue class based on java.util.LinkedList class. Your Queue class should have an enqueue(), dequeue(), peek(), and isEmpy() methods. Create a new Java Application that has the following methods: A method to randomly generate a number of elements between two given values and save them in a queue A method to print a queue (10 elements per line). The original queue should remain as is after the print A method to return the number of elements on the...
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...