Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 18, Problem 12RQE
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.
Example: Cookies in a container.
The baker arranges the cookies one by one in a container in which the lastly inserted cookie is taken out first (pop operation) from the container.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
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.
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.
Suppose the following operations were performed on an empty stack:
push (0);
push (9);
push (12);
push (1);
Insert numbers in the following diagram to show what will be stored in the static stack
after the operations have executed.
top of stack
bottom of stack
Chapter 18 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 18.3 - Describe what LIFO means.Ch. 18.3 - What is the difference between static and dynamic...Ch. 18.3 - What are the two primary stack operations?...Ch. 18.3 - What STL types does the STL stack container adapt?Ch. 18 - Prob. 1RQECh. 18 - Prob. 2RQECh. 18 - What is the difference between a static stack and...Ch. 18 - Prob. 4RQECh. 18 - The STL stack is considered a container adapter....Ch. 18 - What types may the STL stack be based on? By...
Ch. 18 - Prob. 7RQECh. 18 - Prob. 8RQECh. 18 - Prob. 9RQECh. 18 - Prob. 10RQECh. 18 - Prob. 11RQECh. 18 - Prob. 12RQECh. 18 - Prob. 13RQECh. 18 - Prob. 14RQECh. 18 - Prob. 15RQECh. 18 - Prob. 16RQECh. 18 - Prob. 17RQECh. 18 - Prob. 18RQECh. 18 - Prob. 1PCCh. 18 - Prob. 2PCCh. 18 - Prob. 3PCCh. 18 - Prob. 4PCCh. 18 - Prob. 5PCCh. 18 - Prob. 6PCCh. 18 - Prob. 7PCCh. 18 - Prob. 8PCCh. 18 - Prob. 14PCCh. 18 - Prob. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PCCh. 18 - Prob. 15PC
Knowledge Booster
Similar questions
- If the elements “A”, “B”, “C” and “D” are placed in a stack and are removed one at a time, in what order will they be removed?arrow_forward3- Write a program that randomly generates 10 numbers (between 1 and 8), inserts into queue and then finds how many distinct elements exist in the queue. Example 1: Example 2: Queue: 2 40 3 3 2 18 4 18 18 3 Queue: 1 1 4 33 16 16 4 16 4 Output: 5 Output: 4 Notes: • You must use ONLY queue data structure. Don't use other different data structures like string or normal (pure) array or stack or array list. • Don't write any other method in the Qeueu class. All methods must be written in the main program.arrow_forward10 - final question If you create a new empty stack and push the values 1, 2, and 3 in that order, and call pop on the stack once, Which value will be returned? а. 1 b. 2 С. 3arrow_forward
- Q1: Write a java application for the stack operations with Linked List. Q2: Write java program to take the order from the customer and display the ordered items and total payment. If customer is entering the wrong name or not following the order to enter the menu it has to display error messages. (Find in the sample code) Sample Output:arrow_forwardConsider 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?arrow_forward3- 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_forward
- checkBalance Language/Type: Java Stack collections string Related Links: String Write a method named checkBalance that accepts a string of source code and uses a Stack to check whether the braces/parentheses are balanced. Every ( or { must be closed by a } or ) in the opposite order. Return the index at which an imbalance occurs, or -1 if the string is balanced. If any ( or { are never closed, return the string's length. Here are some example calls: // index 0123456789012345678901234567890 checkBalance("if (a(4) > 9) { foo(a(2)); }") returns -1 because balanced checkBalance("for (i=0;i<a(3};i++) { foo{); )") // returns 14 because } out of order checkBalance("while (true) foo(); }{ ()") returns 20 because } doesn't match any { checkBalance("if (x) {") returns 8 because { is never closed // // // Constraints: Use a single stack as auxiliary storage.arrow_forwardIn c++ Also add comments explaining each linearrow_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_forward2. Write an application utilizing JAVA-ready Stack class and perform the following. Create a new instance of the Stack of type double. Use a loop to get 5 input from the user and insert into the stack created. The inputs are 3.4, 10.1, 10.3, 11.5, 3.5. Write a statement to display the content of the stack. Perform pop() all elements and display on the screen if the number is greater than 5.0. Use the output sample given to guide your code. Sample output: [3.4, 10.1, 10.3, 11.5, 3.5] 11.5 10.3 10.1arrow_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_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