Which elements would be on the stack after executing the following lines of code (listed from...
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:
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...
JAVA Lab Create a class called ArrayBasedStack. Declare the following variables: • data: references an array storing elements in the list • topOfStack: an int value representing the location of the stack top in the array • INITIAL_CAPACITY: the default capacity of the stack public class ArrayBasedStack <E> { private E[] data; private int topOfStack; private static final int INITIAL_CAPACITY = 5; } Add a constructor that will initialize the stack with a user-defined initial capacity. The top of the...
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...
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...
4. Given a stack variable stk which provides a push operation that places an integer o top of the stack, and a pop operation which removes and returns the integer from t top of the stack, what would the stack look like, after the following code executed? for(int k 1; k < 10; k++) if(k % 3 :0) stk.push( k+ stk.pop()); else stk.push( k); 25. Given a queue variable que which provides an add operation which places an integer at...
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....
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...
C++
Carefully review Program 19-2 in your textbook,
MathStack. This is a static stack, meaning that the size
of the stack is set at the beginning of the program (see line 11):
MathStack stack(5).
I would like you to modify this program as follows:
1. Implement it as a dynamic stack (do not use a static
stack as it is designed in the book). Use a linked list to
implement this. There's code in the book.
2. Add functionality for...
Consider the following circular array queue. Indicate what would be printed when executing the following code (assuming array is the variable containing the elements): count 5 front XHL se 2 rear 0 1 2 3 4 N int t = front; for (int q = 0; q < count; q++) { System.out.print(array(q) + t = (t + 1) % array.length; } ");