Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help me problem 13 m of the stack is now at the top, the value th value that was second from the bottom is
please help me problem 13
m of the stack is now at the top, the value th value that was second from the bottom is now third from bird from the values fronil 4, 5, 6, 7, 8), and we nuk of the stack to the top of the stack and leave the other 3. 2. 11. Notice that the value that was at the bottom of the sh from the bottom is now second from the top, the value that we and that the five values not involved in the shift are now at the botto queue as auxiliary storage. You may assume that the parameter niso ments in the stack. at the bottom of the stack in their origina neter n is 20 and not larger than the numb original order. Uscene han the number of ele 13. Write a method called expunge that accepts a stack of integers as a param ments are in nondecreasing order nondecreasing order from top to bottom, by removing from the stack any element that (s) on top of it. For example, if the stack stores [4, 20, 15, 15, 8, 5, 7, 12 7. 5. 3, and 4 should be removed because each has an element above it w our method should change the stack to store [20, 15, 15, 12, 10, 5, 1]. Notice that ments are in nondecreasing order from top to bottom. If the stack is empty or has just one element Use one queue or stack (but not both) as auxiliary storage. and makes sure that the stack's ele stack any element that is smaller than . 5, 7, 12, 3, 10, 5, 11 ement above it with a larger 11. Notice that now the cle- has just one element, nothing changes. 4. Write a method called reverseFirstk that accepts an integer k and a queue of integers as parameters and reverses the order of the first k elements of the queue, leaving the other elements in the same relative order. For example, if a queue named a stores (10, 20, 30, 40, 50, 60, 70, 80, 90], the call of reverse- Pirst (4, q); should change the queue to store (40, 30, 20, 10, 50, 60, 70, 80, 90). If k isor negative, no change should be made. If the queue does not contain at least k elements, your method should throw IllegalArgumentException. Use one queue or stack (but not both) as auxiliary storage. ed issorted that accepts a stack of integers as a parameter and returns true if the ments in the stack occur in ascending (nondecreasing) order from top hould be on ton orawina la ng (nondecreasing) order from top to bottom. That is, the smallest eleme Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started