EBK STARTING OUT W/JAVA:...DATA...
4th Edition
ISBN: 9780134757179
Author: GADDIS
Publisher: PEARSON CO
expand_more
expand_more
format_list_bulleted
Question
Chapter 20.3, Problem 20.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 20 Solutions
EBK STARTING OUT W/JAVA:...DATA...
Ch. 20.3 - Prob. 20.1CPCh. 20.3 - Prob. 20.2CPCh. 20.3 - Prob. 20.4CPCh. 20.3 - Prob. 20.5CPCh. 20.6 - Prob. 20.6CPCh. 20.6 - Prob. 20.7CPCh. 20.6 - Prob. 20.8CPCh. 20.6 - Prob. 20.9CPCh. 20 - Prob. 1MCCh. 20 - Prob. 2MC
Ch. 20 - Prob. 3MCCh. 20 - The concept of seniority, which some employers use...Ch. 20 - Prob. 5MCCh. 20 - Prob. 6MCCh. 20 - Prob. 8TFCh. 20 - Prob. 9TFCh. 20 - Prob. 10TFCh. 20 - Prob. 1FTECh. 20 - Prob. 2FTECh. 20 - Prob. 3FTECh. 20 - Prob. 4FTECh. 20 - Prob. 5FTECh. 20 - Prob. 1AWCh. 20 - Prob. 2AWCh. 20 - Suppose that you have two stacks but no queues....Ch. 20 - Prob. 1SACh. 20 - Prob. 2SACh. 20 - Prob. 3SACh. 20 - Prob. 4SACh. 20 - Prob. 5SACh. 20 - 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_forwardWrite a c program and fill a queue with random numbers between 0 and 100. The size of thequeue is assumed to be 15. After filling the array with random numbers, display the elementsin the queue and remove the elements of the queue and store these numbers according to thefollowing criteria.If the number in the queue is less than 50, remove it from the queue and store it insidequeue 2.Else, remove the number and store these values inside queue 3.Display all three queues on the screen.arrow_forward
- Many 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_forwardin 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_forward
- Design and implement an application that reads a sentence fromthe user and prints the sentence with the characters of each wordbackwards. Use a stack to reverse the characters of each word.8. Pop the infix expression off the stack and print it.arrow_forwardPlease 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_forward
- Complete the following ():a. A stack is used by the system when a function call is madeb. A stack can become full during program executionarrow_forwardUsing C++, please help me to solve this problem.arrow_forwardExamine the stack's performance when it is allowed to operate in its natural state.arrow_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