1)
push(5): stack: 5<-top
push(3): stack: 5,3<-top
size(): returns 2
pop(): stack :5<-top
isEmpty(): returns false
pop(): stack:<-top
isEmpty(): returns true
pop(): error msg:stack is empty
push(7): stack:7<-top
push(9): stack:7,9<-top
top():returns 9
push(4): stack:7,9,4<-top
size():returns 3
pop(): stack:7,9<-top
push(6): stack:7,9,6<-top
push(8): stack:7,9,6,8<-top
pop(): stack:7,9,6<-top
Note: As per HOMEWORKLIB POLICY, I am allowed to answer only 1
question(including sub-parts)
on a single post, kingly post the remaining questions seperately
and i will try to answer them
Sorry for the inconvenience caused, thank you
Stacks and queues 1. Show the status of the stack or return values along with the...
ae two stacks, a number stack and an operator stack, to evaluate the tollowing algebraic expression (6+2*8/(16-4*3))/2 Read the items in the expression one at a time from left to right. Show the number stack and the operator stack after each item in the expression has been read and processed. If processing an item involves evaluating the top, show the two stacks af and then show the two stacks again after a "(” , if any, is popped off or...
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...
Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The application will be to add large numbers. Review adding large numbers Remember that we can use stacks to safely add integer values that overflow the int data type g. in Java, the maximum possible int value Integer.MAX_VALUE is: 2147483647 so any int addition larger than this will overflow and fail Using stacks to add large numbers safely Will actually represent the large integers to...
) Consider Java's Stack class, and its five standard stack operations: push, pop, peek, isEmpty, and clear. Complete the two unfinished methods. Do not modify any other parts of the class. // Looks at the top two elements of the stack, and removes and returns the larger // of the two elements from the stack, returning the other element to the stack. // For example, if the stack, from the top, is 8 10 7 2...
Backtracking is a computing algorithm using stack to “remember” user-generated events when using a program. A user event may be “pressing the Enter key on keyboard” or “clicking a mouse button”. Stack is a data structure with the Last-In-First-Out property (LIFO). If we push the aforesaid user events into a stack, a computer program using that data structure can “rewind” user events by popping them out of stack one at a time. This backtracking feature is available as Edit ->...
Stacks and Java 1. Using Java design and implement a stack on an array. Implement the following operations: push, pop, top, size, isEmpty. Make sure that your program checks whether the stack is full in the push operation, and whether the stack is empty in the pop operation. None of the built-in classes/methods/functions of Java can be used and must be user implemented. Practical application 1: Arithmetic operations. (a) Design an algorithm that takes a string, which represents an arithmetic...
c program Here we see a Stack ADT implemented using array. We would like the stack to be usable for different max sizes though, so we need to use dynamic memory allocation for our array as well. #include <stdio.h> #include <stdlib.h> typedef struct { int *data; // stack data, we assume integer for simplicity int top; // top of the stack int maxSize; // max size of the stack } Stack; void StackInit(Stack* stack, int size) { // this...
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....
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...
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...