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 13RQE
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
Stack:
Stacks are a type of container with LIFO (Last In First Out) type of working, where a new element is added at one end and (top) an element is removed from that end only. Your Stack should not be of the fixed sized. It should be able to grow itself. So using the class made in task 1, make a class named as Stack, having following additional functionalities:
bool empty() : Returns whether the Stack is empty or not. Time Complexity should be: O(1)
bool full() : Returns whether the Stack is full or not. Time Complexity should be: O(1)int size() : Returns the current size of the Stack. Time Complexity should be: O(1)Type top () : Returns the last element of the Stack. Time Complexity should be: O(1)
void push(Type) : Adds the element of type Type at the top of the stack. Time Complexity should be: O(1)
Type pop() : Deletes the top most element of the stack and returns it. Time Complexity should be: O(1)
Write non-parameterized constructor for the above class.
Write Copy…
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.
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
- Suppose 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_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_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_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_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_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_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_forwardcheckBalance 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_forward
- In the following code, assume myStack is a stack that holds integers. What would be the contents of the stack after the following operations, indicating what element is currently at the top and the bottom of the stack. myStack.push(1);myStack.push(2);myStack.push(3);myStack.pop();myStack.push(4);myStack.push(5);myStack.pop(); Group of answer choices 4 <- Top21 <- Bottom 5 <- Top31 <- Bottom 4 <- Top32 <- Bottom 5 <- Top21 <- Bottomarrow_forwardIn c++ Also add comments explaining each linearrow_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