Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 19, Problem 23RQE
Program Plan Intro
Stack:
A stack is type of container. It performs “Last In First Out”.
- In stack, the item which is inserted at last will be retrieved first.
- A stack can perform two operations. They are:
- Push – Inserting an element inside a stack.
- When the first element is pushed into the stack, the element will be at the “top” the stack. When the second element is added, the first element is pushed down and the second element will be at the top position, like this it goes on until the element which pushed at last will be at the top of the stack.
- Pop – Deleting an element from the stack.
- The element which is inserted at last will be deleted first.
- Push – Inserting an element inside a stack.
- The elements can be inserted and retrieved at any one end of the stack.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
C#
Reverse the stack - This procedure will reverse the order of items in the stack. This one may NOT break the rules of the stack. HINTS: Make use of more stacks. Arrays passed as parameters are NOT copies. Remember, this is a procedure, not a function.
This would occur in the NumberStack class, not the main class. These are the provided variables:
private int [] stack;private int size;
Create a method that will reverse the stack when put into the main class.
First picture: create a complete programming codes about the picture. Use pre-defined for stack.
Sencond Picture: Test results or the supposed outcome of the programming.
Note: put a comment in every line to describe what is the function of each specific codes, variables, etc.
Consider the following statements:
linkedStackType<int> stack;
linkedQueueType<int> queue;
int num;
Suppose the input is
28 30 15 11 10 -9 21 8 -3 33 17 14
Write a C++ code that processes these numbers as follows: If the number is an even number, it is pushed onto the stack. If the number is odd and divisible by 3, it is added into the queue; otherwise the top element, if any, of the stack is removed and the square of the number is added onto the stack. After processing these numbers, what is stored in stack and queue?
Chapter 19 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 19.1 - Describe what LIFO means.Ch. 19.1 - What is the difference between static and dynamic...Ch. 19.1 - What are the two primary stack operations?...Ch. 19.1 - What STL types does the STL stack container adapt?Ch. 19 - Prob. 1RQECh. 19 - Prob. 2RQECh. 19 - What is the difference between a static stack and...Ch. 19 - Prob. 4RQECh. 19 - Prob. 5RQECh. 19 - The STL stack is considered a container adapter....
Ch. 19 - What types may the STL stack be based on? By...Ch. 19 - Prob. 8RQECh. 19 - Prob. 9RQECh. 19 - Prob. 10RQECh. 19 - Prob. 11RQECh. 19 - Prob. 12RQECh. 19 - Prob. 13RQECh. 19 - Prob. 14RQECh. 19 - Prob. 15RQECh. 19 - Prob. 16RQECh. 19 - The STL stack container is an adapter for the...Ch. 19 - Prob. 18RQECh. 19 - Prob. 19RQECh. 19 - Prob. 20RQECh. 19 - Prob. 21RQECh. 19 - Prob. 22RQECh. 19 - Prob. 23RQECh. 19 - Prob. 24RQECh. 19 - Prob. 25RQECh. 19 - Prob. 26RQECh. 19 - Write two different code segments that may be used...Ch. 19 - Prob. 28RQECh. 19 - Prob. 29RQECh. 19 - Prob. 30RQECh. 19 - Prob. 31RQECh. 19 - Prob. 32RQECh. 19 - Prob. 1PCCh. 19 - Prob. 2PCCh. 19 - Prob. 3PCCh. 19 - Prob. 4PCCh. 19 - Prob. 5PCCh. 19 - Dynamic String Stack Design a class that stores...Ch. 19 - Prob. 7PCCh. 19 - Prob. 8PCCh. 19 - Prob. 9PCCh. 19 - Prob. 10PCCh. 19 - Prob. 11PCCh. 19 - Inventory Bin Stack Design an inventory class that...Ch. 19 - Prob. 13PCCh. 19 - Prob. 14PCCh. 19 - Prob. 15PC
Knowledge Booster
Similar questions
- 3- Evaluate the following statement using stack : T= calculate (3) ; Where calculate () defined as follows : int calculate ( int n) { int x , y; if ( n<=1) return 1; else { x = calculate (n – 1) ; y = calculate ( n - 2 ); return x * y; } }arrow_forwardquestion is given below question is given below question is given below question is given below question is given below question is given below question is given below question is given below question is given below question is given below question is given below question is given belowarrow_forward1. A company wants to evaluate employee records in order to lay off some workers on the basis of service time (the most recently hired employees are laid off first). Only the employee ids are stored in stack. Write a program using stack and implement the following functions: Main program should ask the appropriate option from the user, until user selects an option for exiting the program. Enter_company (emp_id)- the accepted employee id(integer) is pushed into stack. Exit_company ()- The recently joined employee will be laid off from the company Show employee ()- display all the employees working in the company. count()- displays the number of employees working in the company. i) ii) iii) iv)arrow_forward
- 1. A company wants to evaluate employee records in order to lay off some workers on the basis of service time (the most recently hired employees are laid off first). Only the employee ids are stored in stack. Write a program using stack and implement the following functions: Main program should ask the appropriate option from the user, until user selects an option for exiting the program. Enter_company (emp_id)- the accepted employee id(integer) is pushed into stack. Exit_company ()- The recently joined employee will be laid off from the company Show_employee ()- display all the employees working in the company. count()- displays the number of employees working in the company. i) ii) iii) iv)arrow_forwardAssume the function: void F(stack<T> &S){ } and we send a stack S to the function F, as a result of it Select one: a. Copy constructor should be called b. Both (copy constructor and destructor) should be called c. Both (copy constructor and destructor) should not be called d. Destructor should be calledarrow_forwardIn c++ Also add comments explaining each linearrow_forward
- Assume the function: void F(stack &S){ } and we send a stack S to the function F, as a result of it Select one: a. Both (copy constructor and destructor) should be called b. Destructor should be called O c. Copy constructor should be called d. Both (copy constructor and destructor) should not be calledarrow_forwardQuestion3. Using the Stack class implemented in JAVA, write a JAVA code to do the following: a. Create an array of integers containing the following elements: 5, -1, 7,8,9,4,15 b. Create an empty stack (call it nums) and push all the array elements onto the stack. c. Using a temporary stack to reverse the content of the stack nums then print it. d. Display all odd elements from the stack nums.arrow_forwardAssume the function: void F(stack<T> &S){ } and we send a stack S to the function F, as a result of it Select one: a. Both (copy constructor and destructor) should not be called b. Destructor should be called c. Copy constructor should be called d. Both (copy constructor and destructor) should be called Clear my choicearrow_forward
- 3- Evaluate the following statement using stack : T=sumSquares (4,6); Where sumSquares ( ) defined as follows : int sumSquares ( int n , int m ) { int middle ; if ( n == m ) return m*m; else {middle = (n+m) /2 ; return sumSquares (n, middle)+sumSquares (middle+1,m); }arrow_forwardProblem 1: Complete the following method for reversing the contents of a given stack. The method should use only the constructor and the methods push(), pop() and isEmpty(). Assume that the methods push(), pop() and isEmpty() methods are defined as they should be in a Stack class. Assume further that the Stack class has no argument constructor. Note: make sure that you don't include unnecessary spaces in your answers. public void reverse(Stack stack) { Stack tempStack1 = new Stack(); %3D while (!stack.isEmpty()) { tempStack1.push(_#01 ); } Stack tempStack2 = new Stack(); while (!tempStack1.isEmpty()) { tempStack2.push(_ #02 ); } while (!tempStack2.isEmpty()) { stack.push(_ #03 ); } }arrow_forwardTOPICS: LIST/STACK/QUEUE Write a complete Java program about Appointment schedule(anything). Your program must implements the linked list The program should have the following basic operations of list, which are: a) Add first, in between and last b) Delete first, in between and last c) Display all data The program should be an interactive program that allow user to choose type of operation.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning