






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...
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...
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...
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...
PART A - STACKS To complete this assignment: Please study the code posted below. Please rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same *************************************************************************************************************** /** * Stack implementation using array in C/procedural language. */ #include <iostream> #include <cstdio> #include <cstdlib> //#include <climits> // For INT_MIN #define SIZE 100 using namespace std; /// Create a stack with capacity of 100 elements int stack[SIZE]; /// Initially stack is...
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...
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;...
Convert following code to implement linked list C++ language #include<iostream> using namespace std; int top = -1; //globally defining the value of top, as the stack is empty void push(int stack[], int x, int n) { if (top == -1) //if top position is the last of posiition of stack,means stack is full { cout << "Stack is full Overflow condition"; } else { top = top + 1; //incrementing top position stack[top] = x; //inserting element on incremented position...
Code in C++. Can someone make it so that the code below can be compiled? ▪ Creating an empty queue ▪ Inserting a value ▪ Removing a value ▪ Finding the size of the queue ▪ Printing the contents of the queue ▪ Adding the contents of one queue to the end of another ▪ Merging the contents of two queues into a third, new, queue Class Attributes Your class should be implemented using a linked list and should have...
Help me solve this in C++ 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. You can prepare a class if you wish but it is not required. /** * Queue implementation using linked list C style implementation ( no OOP). */ #include <cstdio> #include <cstdlib> #include <climits> #include <iostream> #define CAPACITY 100 // Queue max...
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....