/* here in this program as per the question variable back is taken as rear named variable */
/* enqueue member function */
template <class X>
void ArrQueue <X>::enqueue(X item)
{
if(front==-1)
{
front = 0;
}
rear=(rear+1)%sz;
items[rear]=item;
cout<<endl<<"Inserted :
"<<item<<endl;
}
/* dequeue member function */
template <class X>
X ArrQueue <X>::dequeue()
{
X element;
element=items[front];
if(front==rear){
front=-1;
rear=-1;
}
else
{
front=(front+1)%sz;
}
return(element);
}
/* peek Front memeber function */
template <class X>
X ArrQueue <X>::peekFront()
{
if(front>=0)
cout<<"peek front element is :"<<
items[front];
else
cout<<"No peek element in queue";
}
/* isEmpty member function */
template <class X>
void ArrQueue <X>::isEmpty()
{
if(front==-1)
{
cout<<"Circular Queue is
empty";
}
else
{
cout<<"Circular Queue is not empty";
}
}
/* ArrQueue class with template */
template <class X>
class ArrQueue
{
X *items; // dynamically allocated array
//
int capacity;
int front;
int rear;
int count;
public:
ArrQueue (int size=sz); // constructor
//
X dequeue(); // delete element//
void enqueue(X x); // insert element //
X peekFront(); // front element //
int size(); // count elements //
void isEmpty(); // check empty or not //
void display(); // display queue //
};
/* full program */
/* here for better under standing the full program is given, which will help to co relate the above functions and other functions with rest of the program */
/* here in this program as per the question variable back is taken as rear named variable */
#include <iostream>
#include <cstdlib>
using namespace std;
// max size of queue is 20//
#define sz 20
// template class representation of circular queue //
template <class X>
class ArrQueue
{
X *items; // dynamically allocated array
//
int capacity;
int front;
int rear; // as per the question back named variable
//
int count;
public:
ArrQueue (int size=sz); // constructor
//
X dequeue(); // delete element//
void enqueue(X x); // insert element //
X peekFront(); // front element //
int size(); // count elements //
void isEmpty(); // check empty or not //
void display(); // display queue //
};
template <class X>
ArrQueue <X>::ArrQueue(int size)
{
items = new X[size]; // dynamically allocate in
circular array//
capacity = size;
front = -1;
rear = -1;
count = 0;
}
// return type is X which is integer //
template <class X>
X ArrQueue <X>::dequeue()
{
X element;
element=items[front];
if(front==rear){
front=-1;
rear=-1;
}
else
{
front=(front+1)%sz;
}
return(element);
}
template <class X>
void ArrQueue <X>::enqueue(X item)
{
if(front==-1)
{
front = 0;
}
rear=(rear+1)%sz;
items[rear]=item;
cout<<endl<<"Inserted :
"<<item<<endl;
}
template <class X>
void ArrQueue <X>::display()
{
int index;
if(front==-1)
{
cout<<"No element is found to be
displayed";
}
else
{
cout<<endl<<"Items in the Circular Queue are: \n
";
for(index=front;index!=rear;index=(index+1)%sz)
{
cout<<items[index]<<"
";
}
cout<<items[index];
}
}
template <class X>
X ArrQueue <X>::peekFront()
{
if(front>=0)
cout<<"peek front element is :"<<
items[front];
else
cout<<"No peek element in queue";
}
template <class X>
int ArrQueue <X>::size()
{
return count;
}
template <class X>
void ArrQueue <X>::isEmpty()
{
if(front==-1)
{
cout<<"Circular Queue is
empty";
}
else
{
cout<<"Circular Queue is not empty";
}
}
int main()
{
// here template X is int //
ArrQueue <int> q;
int ch,val,p;
char ch1;
do
{
cout<<"1.Enque"<<endl;
cout<<"2.Deque"<<endl;
cout<<"3.isEmpty"<<endl;
cout<<"4.Peek
Front"<<endl;
cout<<"5.Display"<<endl;
cout<<"Enter the choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter the item
:";
cin>>val;
q.enqueue(val);
break;
case 2:
p=q.dequeue();
cout<<"Removed element
is:"<<p;
break;
case 3:
q.isEmpty();
break;
case 4:
q.peekFront();
break;
case 5:
q.display();
break;
default:
cout<<endl<<"Wrong option[ Enter from
1,2,3,4,5]"<<endl;
}
cout<<endl<<"Want to
continue[Y/y]:";
cin>>ch1;
} while(ch1=='Y' || ch1=='y');
}
SCREEN SHOT
OUTPUT
please write them in parts and not the whole code Page 3 of 5 based queue...
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...
Suppose we have an array-based queue (circular buffer) of size 6: int data[6]; int front = 0, back = 0; void enqueue(int x) { data[back] = x; back = (back + 1) % 6; } void dequeue() { front = (front + 1) % 6; } and we perform the following series of queue operations: enqueue(1); dequeue(); enqueue(2); dequeue(); enqueue(7); enqueue(3); enqueue(5); dequeue(); dequeue(); enqueue(4); enqueue(6); Write the state of the queue array after each operation, and at the end,...
QUESTION 1: Queue Class: Write a Queue class using doubly-linked structure and implement the following functionalities. enqueue (inserts element to the end) dequeue (removes the front element and provides content) isEmpty (checks whether the Queue is empty or not) makeEmpty () peek (provides the element sitting at the top/front, but does not remove) print (prints all the elements from front to the end) reversePrint(prints all the elements from end to the front with the help of back pointers inside your...
(C++) (VISUAL STUDIO) Circular Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. In a normal Queue, we can insert elements until queue becomes full. But once queue becomes full, we cannot insert the next element even if there is a space in front of queue. Efficiently implement a queue class using a circular...
e. public class Queue { // Uses the correct Stack class from ME2 Ex 19 private Stack mStack; public Queue() { setStack(new Stack()); } public Queue enqueue(E pData) { getStack().push(pData); return this; } public E dequeue() { return getStack().pop(); } public E peek() { return getStack.peek(); } private Stack getStack() { return mStack; } private void setStack(Stack pStack) { mStack = pStack; } } f. public class Queue extends Stack { // Uses the correct Stack class from ME2 Ex...
You need to implement a queue based on the doubly linked list. (In C++) **PLEASE follow the format** **Don't worry about the readme.txt** THANK YOU SO SO MUCH! You have to implement the doubly linked list in DList.h and DList.cpp and the queue in the LinkedQueue.h and LinkedQueue.cpp; all as template classes. You have to provide the main.cpp file as we discussed in class to allow the user to interact with your queue using enqueue, dequeue, front, back, size, empty,...
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...
I need help fixing my code. My output should be the following. Hello, world! : false A dog, a panic in a pagoda : true A dog, a plan, a canal, pagoda : true Aman, a plan, a canal--Panama! : true civic : true If I had a hi-fi : true Do geese see God? : true Madam, I’m Adam. : true Madam, in Eden, I’m Adam. : true Neil, a trap! Sid is part alien! : true Never odd...
Write only function. In c++ 3. a) Write a function, to be included in a queue class - circular array implementation (20 p that will print all the items in the queue from front to rear
AQueue.java class AQueue implements Queue { private E queueArray[]; // Array holding queue elements private static final int DEFAULT_SIZE = 10; private int maxSize; // Maximum size of queue private int front; // Index of front element private int rear; // Index of rear element // Constructors @SuppressWarnings("unchecked") // Generic array allocation AQueue(int size) { //BUG #1: maxSize = size maxSize = size+1; // One extra space is allocated rear = 0; front = 1; queueArray = (E[])new Object[maxSize]; //...