Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
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
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
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?
Chapter 18 Solutions
Starting Out with C++: Early Objects (9th 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. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PCCh. 18 - Prob. 14PCCh. 18 - Prob. 15PC
Knowledge Booster
Similar questions
- 3- 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_forwardQ1: 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_forward
- 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?arrow_forwardIn c++ Also add comments explaining each linearrow_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
- 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 below question is given belowarrow_forwardSuppose the following operations were performed on an empty stack:pus h(8);pus h(?);pop();push (19);pus h(21);pop();Insert numbers in the following diagram to show what will be stored in the staticstack after the operations have executedarrow_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_forward
- When a stack is created, what are the initial values in the elements array?arrow_forwardAssume s1,s2 are two stacks and we write s1=s2 , if the class stack based on linked list then Select one: a. This statement is good when s2 has large number of items and s1 has small number of items b. This statement is good when s2 has small number of items and s1 has small number of items c. This statement is good when s2 has large number of items and s1 has large number of items d. This statement is good when s2 has small number of items and s1 has large number of itemsarrow_forwardAssume 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_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