I am to implement a simple simulation that supports a stack and a queue of items being either enqueued and dequeued (onto the queue) or pushed and popped (onto the stack). I are required to use STL data structures to implement and create the stack and queue for my program.
----- testfile1.tst --------
enqueue 5
enqueue 7
push blooper
push rookie
dequeue
push demerits
pop
enqueue 3
enqueue 8
push showplace
enqueue 9
dequeue
pop
dequeue
push palmetto
push zebra
pop
push collapse
dequeue
dequeue
dequeue
pop
pop
pop
pop
pop
enqueue 2
enqueue 4
push penguins
push sleeping
exit
The output should look as shown below:
Enque : 5
Stack :
Queue : 5
Enque : 7
Stack :
Queue : 5 7
Push : blooper
Stack : blooper
Queue : 5 7
Push : rookie
Stack : rookie blooper
Queue : 5 7
Dequeue: 5
Stack : rookie blooper
Queue : 7
Push : demerits
Stack : demerits rookie blooper
Queue : 7
Popped : demerits
Stack : rookie blooper
Queue : 7
Enque : 3
Stack : rookie blooper
Queue : 7 3
Enque : 8
Stack : rookie blooper
Queue : 7 3 8
Push : showplace
Stack : showplace rookie blooper
Queue : 7 3 8
Enque : 9
Stack : showplace rookie blooper
Queue : 7 3 8 9
Dequeue: 7
Stack : showplace rookie blooper
Queue : 3 8 9
Popped : showplace
Stack : rookie blooper
Queue : 3 8 9
Dequeue: 3
Stack : rookie blooper
Queue : 8 9
Push : palmetto
Stack : palmetto rookie blooper
Queue : 8 9
Push : zebra
Stack : zebra palmetto rookie blooper
Queue : 8 9
Popped : zebra
Stack : palmetto rookie blooper
Queue : 8 9
Push : collapse
Stack : collapse palmetto rookie blooper
Queue : 8 9
Dequeue: 8
Stack : collapse palmetto rookie blooper
Queue : 9
Dequeue: 9
Stack : collapse palmetto rookie blooper
Queue :
Dequeue request from empty queue
Stack : collapse palmetto rookie blooper
Queue :
Popped : collapse
Stack : palmetto rookie blooper
Queue :
Popped : palmetto
Stack : rookie blooper
Queue :
Popped : rookie
Stack : blooper
Queue :
Popped : blooper
Stack :
Queue :
Pop request from empty stack
Stack :
Queue :
Enque : 2
Stack :
Queue : 2
Enque : 4
Stack :
Queue : 2 4
Push : penguins
Stack : penguins
Queue : 2 4
Push : sleeping
Stack : sleeping penguins
Queue : 2 4
Simulation ends
#include <iostream>
#include <stack>
#include <queue>
#include <stack>
#include <sstream>
#include <algorithm>
using namespace std;
stack <string> s;
queue <int> q;
void enqueue(int n) {
q.push(n);
}
void dequeue() {
if (q.empty()) {
cout << "QUEUE IS EMPTY"
<< endl;
}
else {
q.pop();
}
}
void push(string str) {
s.push(str);
}
void pop() {
if (s.empty()) {
cout << "STACK IS EMPTY"
<< endl;
}
else {
s.pop();
}
}
void displayQueue() {
cout << "QUEUE: ";
queue <int> qu;
cout << endl;
if (q.empty()) {
cout << "empty queue"
<< endl;
}
else {
while (!q.empty())
{
cout << "
";
qu.push(q.front());
cout <<
q.front();
q.pop();
}
if (qu.empty()) {
cout <<
"empty queue" << endl;
}
while (!qu.empty()) {
q.push(qu.front());
qu.pop();
}
}
cout << endl;
}
void displayStack() {
cout << "STACK: ";
stack <string> sr;
cout << endl;
if (s.empty()) {
cout << "stack is empty"
<< endl;
return;
}
else {
while (!s.empty())
{
cout << "
";
sr.push(s.top());
cout <<
s.top();
s.pop();
}
if (sr.empty()) {
cout <<
"stack is empty" << endl;
}
while (!sr.empty()) {
cout << "
";
s.push(sr.top());
sr.pop();
}
cout << endl;
}
}
int main()
{
int val = 5;
cout << "Enqueue:" <<
val<<endl;
enqueue(5);
displayStack();
displayQueue();
val = 7;
cout << "Enqueue:" << val <<
endl;
enqueue(7);
displayQueue();
displayStack();
string s="blooper";
cout << "PUSH: " << s << endl;
push("blooper");
s = "rookie";
cout << "PUSH: " << s << endl;
push("rookie");
displayStack();
displayQueue();
dequeue();
displayStack();
displayQueue();
s = "demerits";
cout << "PUSH: " << s << endl;
push("demerits");
displayStack();
displayQueue();
pop();
displayStack();
displayQueue();
val = 3;
cout << "Enqueue:" << val <<
endl;
enqueue(3);
displayStack();
displayQueue();
val = 8;
cout << "Enqueue:" << val <<
endl;
enqueue(8);
displayStack();
displayQueue();
s = "showplace";
cout << "PUSH: " << s << endl;
push("showplace");
displayStack();
displayQueue();
val = 9;
cout << "Enqueue:" << val <<
endl;
enqueue(9);
displayStack();
displayQueue();
dequeue();
displayStack();
displayQueue();
pop();
displayStack();
displayQueue();
dequeue();
displayStack();
displayQueue();
s = "palmetto";
cout << "PUSH: " << s << endl;
push("palmetto");
displayStack();
displayQueue();
s = "zebra";
cout << "PUSH: " << s << endl;
push("zebra");
displayStack();
displayQueue();
pop();
displayStack();
displayQueue();
s = "collapse";
cout << "PUSH: " << s << endl;
push("collapse");
displayStack();
displayQueue();
displayStack();
displayStack();
displayQueue();
dequeue();
displayStack();
displayQueue();
dequeue();
displayStack();
displayQueue();
dequeue();
displayStack();
displayQueue();
pop();
displayStack();
displayQueue();
pop();
displayStack();
displayQueue();
pop();
displayStack();
displayQueue();
pop();
displayStack();
displayQueue();
pop();
displayStack();
displayQueue();
val = 2;
cout << "Enqueue:" << val <<
endl;
enqueue(2);
displayStack();
displayQueue();
val = 4;
cout << "Enqueue:" << val <<
endl;
enqueue(4);
displayStack();
displayQueue();
s = "penguins";
cout << "PUSH: " << s << endl;
push("penguins");
displayStack();
displayQueue();
s = "sleeping";
cout << "PUSH: " << s << endl;
push("sleeping");
displayQueue();
displayStack();
return 0;
}

IF THERE'S ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP
I am to implement a simple simulation that supports a stack and a queue of items being either enqueued and dequeued (ont...
Using either a Stack or Queue, write a C++ program that uses a for loop to push or enqueue 100 integers (values of 1-100) onto a stack or queue. Afterwards, the program should pop or dequeue these values off the stack or queue and write them to one of two textfiles (int.txt and int2.txt) based on whether a value is even or odd. If the popped or dequeued value is even, then that particular value should be written into int2.txt....
(ii) [6 marks] Assume that we have an empty stack S and an empty queue Q. Given a series of stack operations on S as below: Push(S,10), Push(S, 7), Push(S, 23), Pop(S), Push(S, 9), Pop(S), Pop(S) Output the element returned by each Pop operation. Given a series of queue operations on Q as below: Enqueue(0,10),Enqueue(Q,20), Enqueue(0,33), Dequeue(Q), Enqueue(Q,55), Dequeue(Q), Dequeue(Q) Output the element returned by each Dequeue operation. (iii) [8 marks] Given an empty binary search tree T, draw the...
A. Starting with an initially empty stack, after 6 push operations, 3 pop operations, and 2 push operations, the number of elements in the stack would be: B. Starting with an initially empty queue, after 5 enqueue operations, 4 dequeue operations, and 6 enqueue operations, the number of elements in the queue would be:
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...
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....
In C++ Implement a queue data structure using two stacks. Remember a queue has enqueue and dequeue functions. You could use either the array or linked list implementation for stacks and queues. Source for stack array: --------------------------------------------------- #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...
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...
I need a method that takes two parameters, one is Queue and other is int n, then I want to use stack and/or queue to reverse the order of n elments in Queue instance. I don't want to use recursion. I want the reverse class with method taking queue and n as parameters and a main method. I want stack class with array implementation with push and pop methods and Queue class with linkedlist implementation with methods deQueue and enQueue...
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...
1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...