Question

elements 19) FOR THE STACK BELOW, WHAT IS THE OUTPUT? PUT NUMBERS ON THE LINES 10 points S1.push(45); S1.push(8); S1.push(88) cout<<S1.top()<<endl; S1.pop(); cout<<S1.top()<<endl; S1.pop); cout<<S1.top(<<endl; S1.pop();

please answer this asap and make sure your answer is correct and I promise to give you a thumbs up

0 0
Add a comment Improve this question Transcribed image text
Answer #1

S1.push(45)->inserts 45 into the stack by incrementing top now top will have value 0 now stack has 45
S1.push(8)->inserts 45 into the stack by incrementing top now top will have value 1 now stack has 45, 8
S1.push(88)->inserts 45 into the stack by incrementing top now top will have value 2 now stack has 45, 8, 88

stack follows Last In First Out scheme so 88 will be removed first followed by 8 and 88
now
cout<<S1.top()<<end1; will print 88
S1.pop() will delete 88 from stack and decrements the top and now stacj will have 45, 8

cout<<S1.top()<<end1; will print 8
S1.pop() will delete 8 from stack and decrements the top and now stack will have 45


cout<<S1.top()<<end1; will print 45
S1.pop() will delete 45 from stack and decrements the top and now stack S1 is empty

Add a comment
Know the answer?
Add Answer to:
please answer this asap and make sure your answer is correct and I promise to give...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must be written in C++ Please Lab 11 Due Date: April 25, 2019 Total Points: 15...

    Must be written in C++ Please Lab 11 Due Date: April 25, 2019 Total Points: 15 points The purpose of this lab is to implement and test a static and dy namic stack Part 1: Static Stack In this part, you are going to design a stack of characters. Assume a simple static array implementation. Complete the code below as specified by the comments below const int MAX- 5 // define an alias for the element type class Stack private:...

  • in c++ please include all of the following " template class, template function, singly linked list,...

    in c++ please include all of the following " template class, template function, singly linked list, the ADT stack, copy constructor, operator overloading, "try catch"and pointers Modify the code named "Stack using a Singly Linked List" to make the ADT Stack that is a template class has the code of the destructor in which each node is directly deleted without using any member function. As each node is deleted, the destructor displays the address of the node that is being...

  • please answer these questions asap and make sure your answer is correct and I promise to...

    please answer these questions asap and make sure your answer is correct and I promise to give you a thumbs up QUESTION 9 Bell LaPadula (BLP) is a security model o that can ensure the confidentiality of the classified data as well as its integrity O that can ensure the confidentiality of the classified data but not its integrity O that can ensure neither the confidentiality of the classified data nor its integrity O that can't ensure the confidentiality of...

  • 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 wo...

    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...

  • Please Answer this question using the language of C++. I provide you with the picture of figure 1...

    Please Answer this question using the language of C++. I provide you with the picture of figure 18_02. Thank you. I 7/ Fig. 18.2: Stack.h 2 // Stack class template. #ifndef #de fine 3 STACK-H STACK-H 5 #include 7 template 8 class Stack ( 9 public: 10 I const T& top) 12 13 l/ return the top element of the Stack return stack.frontO; // push an element onto the Stack void push(const T& pushValue) 15 stack push front (pushValue); 17...

  • Need Help ASAP!! Below is my code and i am getting error in (public interface stack)...

    Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame {    static String[][]maze;    public static void main(String[] args)    {    maze=new String[30][30];    maze=fillArray("mazefile.txt");    }    public static String[][]fillArray(String file)    {    maze = new String[30][30];       try{...

  • Hello, please correct the following C++ CODE it is not working on visual studio: (I WILL RATE, NO...

    Hello, please correct the following C++ CODE it is not working on visual studio: (I WILL RATE, NO INCOMPLETE OR WRONG SOLUTIONS PLEASE) // CPP program to evaluate a given // expression where tokens are // separated by space. #include using namespace std; // Function to find precedence of // operators. int precedence(char op){ if(op == '+'||op == '-') return 1; if(op == '*'||op == '/') return 2; return 0; } // Function to perform arithmetic operations. int applyOp(int a,...

  • #C++, Programming: Program Design Including Data Structures, 7th Edition, it is too long so i can't...

    #C++, Programming: Program Design Including Data Structures, 7th Edition, it is too long so i can't add the these two file.(unorderedlinked.h and linkedlist.h) as well as the output Please use the file names listed below since your file will have the following components: Ch16_Ex5_MainProgram.cpp - given file //22 34 56 4 19 2 89 90 0 14 32 88 125 56 11 43 55 -999 #include #include "unorderedLinkedList.h" using namespace std; int main() { unorderedLinkedList list, subList; int num;                                                                                                                                   ...

  • Please answer using assembly language Easy68k ONLY. I. Write a program called Sorted Primes to a....

    Please answer using assembly language Easy68k ONLY. I. Write a program called Sorted Primes to a. Find out the prime numbers in a method from the following list (15, 16, 17, 23, 2, 32, 3, 31, 13, 19, 12, 9) and push/store them in a stack and then PRINT. (15 points) b. Sort those prime numbers passed by reference (using PEA) to a second method that you found out from the above list in descending order and then PRINT. (20...

  • help me answer the following questions please 1. Stack (LIFO) & its application 1. Stack overflow...

    help me answer the following questions please 1. Stack (LIFO) & its application 1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking Exercises: 1) Which of the following applications may use a stack? A. parentheses balancing program. B. Keeping track of local variables at run time. C. Syntax analyzer for a compiler. D. All of the above. 2) Consider the usual algorithm for determining whether a sequence of parentheses is balanced....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT