Below is the code for Queue operation using an array -->
#include <iostream>
#include<stdlib.h>
#include<string>
using namespace std;
typedef string el_t;
const int MAX_SIZE = 10;
// Purpose of this program : Implement the operations of queue using an array
// Algorithm :
class Queue {
private :
el_t el[MAX_SIZE];
int front, back;
public :
Queue();
~Queue();
bool isEmpty();
bool isFull();
void add(el_t);
void removeElem(el_t&);
void frontElem(el_t&);
int getSize();
void displayAll();
void goToBack();
};
// constructor
Queue::Queue()
{
front = back = 0;
}
// destructor
Queue::~Queue() { }
bool Queue::isEmpty()
{
return (front == back);
}
bool Queue::isFull()
{
return (back == MAX_SIZE);
}
void Queue::add(el_t newElement)
{
if (isFull()) {
throw "Overflow exception";
}
// insert element at the back
else {
el[back] = newElement;
back++;
}
}
void Queue::removeElem(el_t &removedElem)
{
if (isEmpty())
{
throw "Underflow exception";
}
else
{
removedElem = el[front];
for (int i = 0; i < back - 1; i++) {
el[i] = el[i + 1];
}
// decrement back of the queue
back--;
}
}
void Queue::frontElem(el_t& frontElem)
{
if (isEmpty())
{
throw "Underflow exception";
}
else
{
frontElem = el[front];
}
}
int Queue::getSize()
{
return back + 1;
}
void Queue::displayAll()
{
int i = front;
if (isEmpty()) {
cout<<"[ empty ]"<<endl;
}
else
{
cout<<"[";
for (i = front; i < back; i++) {
cout<<"<-- "<<el[i];
}
cout<<"]";
}
}
void Queue::goToBack()
{
if (isEmpty())
{
throw "Underflow exception";
}
else
{
int arraySize = sizeof(el)/sizeof(el[0]);
if (arraySize > 1)
{
el_t removedElement;
removeElem(removedElement);
add(removedElement);
}
}
}
int main() {
Queue q;
q.add("A");
q.add("B");
q.add("C");
// Intial printing
q.displayAll();
el_t removedElem;
try {
// removing element from front
q.removeElem(removedElem);
// adding element at back
q.add(removedElem);
// print queue after insertion and deletion
q.displayAll();
} catch (exception& e){
cout<<e.what();
} return 0;
}
//Look for** to complete this program --C+ please --please add comments // using namespace std; #include...
Are based on the following Queue class code segment class QueueFull {/* Empty exception class */}; Class Queue Empty {/* Empty exception class */}; struct Node//Node structure int data;//Holds an integer Node* next;//Pointer to next node in the queue}; Class Queue//Linked node implementation of Queue ADT {Private: Node* front;//Pointer to front node of queue Node* rear;//pointer to last node of queue Public: Queue ()://default constructor initializes queue to be empty -Queue ();//Deallocates all nodes in the queue Void Add (int...
HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD COMMENTS: stackARRAY: #include<iostream> #define SIZE 100 #define NO_ELEMENT -999999 using namespace std; class Stack { int arr[SIZE]; // array to store Stack elements int top; public: Stack() { top = -1; } void push(int); // push an element into Stack int pop(); // pop the top element from Stack int topElement(); // get the top element void display(); // display Stack elements from top to bottom }; void Stack...
My Question is: I have to modify this program, even a small modification is fine. Can anyone give any suggestion and solution? Thanks in Advanced. import java.util.*; class arrayQueue { protected int Queue[]; protected int front, rear, size, len; public arrayQueue(int n) { size = n; len = 0; Queue = new int[size]; front = -1; rear = -1; } public boolean isEmpty() { return front == -1; } public boolean isFull() { return front == 0 && rear ==size...
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;...
Create a Java code that includes all the methods from the Lecture slides following the ADTs LECTURE SLIDES Collect/finish the Java code (interface and the complete working classes) from lecture slides for the following ADTS: 4) Queue ADT that uses a linked list internally (call it LQueue) Make sure you keep the same method names as in the slides (automatic testing will be performed)! For each method you develop, add comments and estimate the big-O running time of its algorithm....
Collect/finish the Java code (interface and the complete working classes) from lecture slides for the for the following ADT: 3) Queue ADT that uses an array internally (call it AQueue) Make sure you keep the same method names as in the slides (automatic testing will be performed)! Make sure your classes implement the corresponding interfaces. Put your classes in a package called cse11. Try to make the code robust and try to use generics. The Queue ADT The Queue ADT...
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...
Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...
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 help: Please help complete the locate method that is in bold.. public class LinkedDoubleEndedList implements DoubleEndedList { private Node front; // first node in list private Node rear; // last node in list private int size; // number of elements in list ////////////////////////////////////////////////// // YOU MUST IMPLEMENT THE LOCATE METHOD BELOW // ////////////////////////////////////////////////// /** * Returns the position of the node containing the given value, where * the front node is at position zero and the rear node is...