Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
3rd Edition
ISBN: 9780134038179
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 21, Problem 6MC
Program Description Answer
If a push method is called on an empty stack, it will add its argument to the stack.
Hence, the correct answer is option “B”.
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…
Q2: Write a program that reverses the string "your name" using Stack parameters. You can hardcode your name or you can take it from the user.
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:
Chapter 21 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Ch. 21.3 - Prob. 21.1CPCh. 21.3 - Prob. 21.2CPCh. 21.3 - Prob. 21.4CPCh. 21.3 - Prob. 21.5CPCh. 21.6 - Prob. 21.6CPCh. 21.6 - Prob. 21.7CPCh. 21.6 - Prob. 21.8CPCh. 21.6 - Prob. 21.9CPCh. 21 - Prob. 1MCCh. 21 - Prob. 2MC
Ch. 21 - Prob. 3MCCh. 21 - The concept of seniority, which some employers use...Ch. 21 - Prob. 5MCCh. 21 - Prob. 6MCCh. 21 - Prob. 8TFCh. 21 - Prob. 9TFCh. 21 - Prob. 10TFCh. 21 - Prob. 1FTECh. 21 - Prob. 2FTECh. 21 - Prob. 3FTECh. 21 - Prob. 4FTECh. 21 - Prob. 5FTECh. 21 - Prob. 1AWCh. 21 - Prob. 2AWCh. 21 - Suppose that you have two stacks but no queues....Ch. 21 - Prob. 1SACh. 21 - Prob. 2SACh. 21 - Prob. 3SACh. 21 - Prob. 4SACh. 21 - Prob. 5SACh. 21 - Prob. 6SA
Knowledge Booster
Similar questions
- 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_forwardBriefly describe the stack parameter.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_forward
- 15 - final question When you call pop on a stack, the element is removed from the stack relative to the other elements. а. Тор b. Bottomarrow_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_forwardFirst 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.arrow_forward
- 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.arrow_forwardURGENT URGENT URGENT !!!! Write a void method swapStackwithQueue that takes MyStack and MyQueue Objects as parameters and exchanges the elements. a) The top element of the old stack becomes the rear element of the new queue. b b) and the rear element of the old queue becomes the top element of the new stack. The output should be similar to the image.arrow_forwardCreate your own called class called Stack Your class should store items transparently. You should add items using a Push method and remove them through the Pop method. Add an IsEmpty method should return whether there are any items in the stack or not. A CountItems method should tell you the current number of items in the stack Write some code to test your Stack class using the shapes in part 1.arrow_forward
- ADT stack lets you peek at its top entry without removing it. For some applications of stacks, youalso need to peek at the entry beneath the top entry without removing it. We will call such an operationpeekNxt. If the stack has more than one entry, peekNxt returns the second entry from the top without altering the stack. If the stack has fewer than two entries, peekNxt throws an exception. Write a linkedimplementation of a stack class call LinkedStack.java that includes a method peekNxt. Please make sure that this is included in peekNxt: If the stack has fewer than two entries, peekNxt throws an exception and if you could please make a main to execute peekNxt, thank you.There are 2 class, 1 with the peekNxt, and 1 for implementation. You only need to work on the first one with the peekNxt in it import java.util.EmptyStackException;import java.util.NoSuchElementException;public final class LinkedStack<T> implements StackInterface<T>{private Node topNode;…arrow_forwardCode with comments and output screenshot is must for an Upvote Create a Java function that uses a stack and no arithmetic to compare the number of 0's and 1's in a string. If # of 0's is greater, return -1. If # of 1's is greater, return 1. If equal, return 0.arrow_forwardIn c++ Also add comments explaining each linearrow_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