Question1 ) The STL provides similiar classes called stack and
queue, both of which gave functions called push and pop. Answer the
following questions:
1.1) Does the push perform a different action in the stack class
then in the queue class? Explain the answer.
1.2) Does the pop perform a different action in the stack class then in the queue class? Explain the answer.
Question 2)
2.1) Suppose you are tasked with implementing a reverse queue in which elements are enqueued at the front and dequeued at the rear. The implementation is dynamic, and your queue class has Node pointers called front and rear , which point to the front and rear nodes in the queue. The Node struct is given below:
struct Node
{
char element;
Node * next;
};
a) Implement the enqueue function of the reverse queue.
b) Implement the dequeue function of the reverse queue. The function should return the dequeued value.
(Code should be in C++)
1.1) PUSH
YES. Push() function is used to insert an element at the top of the stack as well as in the queue push function is used to insert an element at the back of the queue.
syntax of push in stack : stackname.push(value).
In the above syntax the stackname indicates the name of the stack which is stored and push is the function we are performing and value is the one which value we want to send into the stack.
IN QUEUE:
push() function is used to insert an element at the back of the queue.when the element is added to the queue the size of the container is increased by 1.
syntax of push in queue: queuename.push(value)
In the above syntax the queuename indicates the name of the queue which is stored and push is the function we are performing and value is the one which value we want to send into the stack.
1.2:) POP(in stack)
pop() function is used to remove an element from the top of the stack which means the new element which is present in the top of the stack.When an element is removed from the stack the size of the stack is reduced /decreased by 1.
syntax: stackname.pop() . we need to give stackname and pop.
ex:
Input : mystack = 0,10,33 mystack.pop(); Output : 0, 10
IN QUEUE :
pop() function is used to remove an element from the front of the queue,which means the old element which is present in the queue is removed using pop in queue.
Input : myqueue = 30, 20, 40 myqueue.pop(); Output : 20, 40
Question1 ) The STL provides similiar classes called stack and queue, both of which gave functions...
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...
Using C
Please comment
» Part A: Stack Create a Stack struct that is a wrapper for your linked list o You should implement the following functions that take a stack o void push(Stack * stack, int value) ● int pop(Stack * stack) Prompt the user to input 5 integers, and use the stack to reverse the integers Print the result to the screen. o o » Part B: Queue o Create a Queue struct that is a wrapper for...
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...
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...
To solve real world problem, the programer uses ADT like list, stack, queue, set, map, ... etc. to build our data model. In AS8, we pick and choose STL queue and stack to build a postfix calculator. In this assignment you are to Design your own linked-list, a series of integer nodes. The private attributes of this IntLinked Queue including a integer node struct and private control variables and methods: private: struct Node { int data; Node *next; }; Node...
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...
// =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations // - (i.e. queue_t* create_queue(unsigned int _capacity) should not have additional arguments) // - You should not have any 'printf' statements in your queue functions. // - (You may consider using these printf statements to debug, but they should be removed from your final version) // ==================================================...
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...
Using C++ in Visual Studios
Rewrite the code to use a Stack instead of a Queue. You will
need to think about the differences in the Stack and Queue. Think
about how they operate and how the nodes may differ.
Modify the code as necessary.
You will need to push to the Stack, pop from the Stack, peek at
the Stack. You will need a member functions like in the example
code. Your program will need to show that everything...
Using C++ Requirements Note: “deque” STL container is not allowed, for the simplicity for graders. Queue Queue is a first-in-first-out (FIFO) data structure. For the Queue container, we will implement a program that simulates a buffer. The simulation needs a function that randomly generate number. And the buffer simulation starts with no value in the buffer. At the start of simulation, the menu should ask user: how many rounds will be simulated. the percentage chance to put a randomly generated...