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
Question
Chapter 21.3, Problem 21.5CP
Program Plan Intro
Stack:
- A stack is a linear data structure.
- The stack follows the order LIFO (last-in-first-out) for performing operations.
- The two main operations performed on stack are,
- Push() – Add item to stack.
- Pop() – Remove item from stack.
“Push()” method:
The “Push()” is a method used to insert or add an item to the stack. The element is pushed at the top of the stack.
- The “Push()” will have an item as its argument and it returns the argument which is passed.
- If the stack is full and when “push()” method is calls the push will generate “StackOverFlowException” and return.
Syntax for push operation:
STACK.push(E element)
“Pop()” method:
- The method “pop()” is used to delete an item from the stack.
- This method does not have any argument and when this method called on a stack, the element at the top of the stack is removed.
- This method will return the top element before removing it.
- If the stack is empty (its size is equal to 0) and when the “pop()” method is called pop throws the “EmptyStackException” object.
Syntax for pop operation:
STACK.pop()
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The stack is a helpful data structure for various computer problems, as demonstrated by the c#bprogramme.
We begin with the rightmost digits and move leftward when changing a decimal number into another format.
The converted digits are in the right sequence after we're done, so pushing each digit up the stack as we go works properly.
Suppose you have a stack with a maximum size of 1000 elements and you want to perform the following operations:
Push 500 elements onto the stack.
Pop 200 elements from the stack.
Push 800 elements onto the stack.
Pop all remaining elements from the stack.
What is the final size of the stack after performing all these operations?
A data structure known as a drop-out stack functions exactly like a stack, with the exception that if the stack size is n, the first element is lost when the n + 1 element is pushed. Use an array to implement a drop-out stack. (Hint: It would make sense to implement a circular array.)
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
- A stack is a collection of things stacked on top of one another. What kind of stack applications are there?arrow_forwardA group of objects that have been piled atop one another is known as a stack. Which kinds of applications make use of stacks are there?arrow_forwardMany real-world situations correspond to a stack. For example, a pile of trays in a cafeteria is a stack since the last tray put on the pile is the first tray used. Think of other real-world stacks and describe the push and pop operations on these.arrow_forward
- in java pls and thank you!arrow_forwardMultiple choice in data structures void stack::do(){ for(int i=0li<=topindex/2;i++){ T temp=entry[i]; entry[i]=entry[topindex-i-1]; entry[topindex-1-i]=temp;} } What is this method do? a. swap the first item with last item b. replace each item with next item value c. doesn't do any thing d. reverse the stackarrow_forwardA drop-out stack is a data structure that acts just like a stack except that if the stack size is n, and the n + 1 element is pushed, the first element is lost. Using an array, create a drop-out stack. (Hint: A circular array implementation would be appropriate.)arrow_forward
- Please help with the following in Java Write a Java program create a stack with elements pushed 1, 2, 3, 4 and 5, removes the middle element. Note that you may use only push(), pop(), peek() and empty() methods of the stack.arrow_forwardIn Python, 1. Elements in a Quene or Stack are removed in the order in which they were added. 2. Elements in a Quene or Stack are removed in reverse order: the most recently added item is the first to be removed. Choose the appropriate choicearrow_forwardComplete the following ():a. A stack is used by the system when a function call is madeb. A stack can become full during program executionarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education