Write A JAVA PROGRAM FOR THE FOLLOWING QUESTION Note: U are not allowed to use inbuilt...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write A JAVA PROGRAM FOR THE FOLLOWING QUESTION Note: U are not allowed to use inbuilt stack or any other features. U should create a stack of your own Explain how you implemented the algorithm. Explanation of main functionalities are enough. Explain about the input format used in each question Use Algorithms, Flowchart of your logic if any. STACK a) Implement a stack using an array. b) Implement a stack using a linked list. Your program must support the following functions: push(element) - puts the data specified by element on top of the stack specified by stk. pop() - removes and returns the topmost element of the stack specified by stk. Return null (or some special value), if the stack is empty. peek() returns the topmost element of the stack specified by stk, without actually removing the element from the stack. Return null (or some special value), if the stack is empty. show() - displays all the data present in the stack specified by stk. . . Activa Go to S Input-Output Format The input consists of multiple lines, each one containing either one or two integers. The first integer in the line can be 0, 1, 2, 3 or 4, and each one has its own meaning: The integer 0 means stop the program. The integer 1 means push the next integer from the input on the stack. In this case, the next integer (>= 0) is given on the same line as the 1, separated by a space. The integer 2 means pop and output the topmost element of the stack. Output "EMPTY", if the stack was originally empty. The integer 3 means peek and output the topmost element of the stack. Output "EMPTY", if the stack was originally empty. The integer 4 means show all elements in the stack. In this case, output all elements of the stack on a single line, separated by space, starting with the top most element. Output "EMPTY", if the stack was originally empty. Sample Input Sample Output 145 1.65 174 1.25 1.98 3.98 3.98 298 3:25 117 4 17 25 74 65 45 217 225 274 2.65 245 2 EMPTY 3 EMPTY 4 EMPTY 0 Note: The above input and output are for the linked list implementation of the stack. For the array implementation, the very first line of input contains an integer c, 0<c< 100, which is the capacity of the stack. In this case, the push operation must output "OVERFLOW" when an element is being tried to be pushed into an already full stack. Other input and output formats remain the same. Write A JAVA PROGRAM FOR THE FOLLOWING QUESTION Note: U are not allowed to use inbuilt stack or any other features. U should create a stack of your own Explain how you implemented the algorithm. Explanation of main functionalities are enough. Explain about the input format used in each question Use Algorithms, Flowchart of your logic if any. STACK a) Implement a stack using an array. b) Implement a stack using a linked list. Your program must support the following functions: push(element) - puts the data specified by element on top of the stack specified by stk. pop() - removes and returns the topmost element of the stack specified by stk. Return null (or some special value), if the stack is empty. peek() returns the topmost element of the stack specified by stk, without actually removing the element from the stack. Return null (or some special value), if the stack is empty. show() - displays all the data present in the stack specified by stk. . . Activa Go to S Input-Output Format The input consists of multiple lines, each one containing either one or two integers. The first integer in the line can be 0, 1, 2, 3 or 4, and each one has its own meaning: The integer 0 means stop the program. The integer 1 means push the next integer from the input on the stack. In this case, the next integer (>= 0) is given on the same line as the 1, separated by a space. The integer 2 means pop and output the topmost element of the stack. Output "EMPTY", if the stack was originally empty. The integer 3 means peek and output the topmost element of the stack. Output "EMPTY", if the stack was originally empty. The integer 4 means show all elements in the stack. In this case, output all elements of the stack on a single line, separated by space, starting with the top most element. Output "EMPTY", if the stack was originally empty. Sample Input Sample Output 145 1.65 174 1.25 1.98 3.98 3.98 298 3:25 117 4 17 25 74 65 45 217 225 274 2.65 245 2 EMPTY 3 EMPTY 4 EMPTY 0 Note: The above input and output are for the linked list implementation of the stack. For the array implementation, the very first line of input contains an integer c, 0<c< 100, which is the capacity of the stack. In this case, the push operation must output "OVERFLOW" when an element is being tried to be pushed into an already full stack. Other input and output formats remain the same.
Expert Answer:
Answer rating: 100% (QA)
Heres a Java program that implements a stack using both an array and ... View the full answer
Related Book For
Modern Database Management
ISBN: 978-0133544619
12th edition
Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi
Posted Date:
Students also viewed these programming questions
-
Divide as indicated. 6x + 10 x-4 9x + 15 2 x 16 X
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Give Three suggestions for a team to engage in professional communication.
-
A particle is described by the normalized wave function (x, y, z) = Axe-ax2 e -y2 e-yz2', where A, a, , and are all real, positive constants. The probability that the particle will be found in the...
-
1. How many cents of energy are required to produce $1 worth of manufactured goods? 2. How many cents of energy are required to produce $1 worth of services? Suppose that a simplified economy...
-
Samantha Montgomery (age 42) is employed by Canon Company and is paid a salary of $62,430. She has just decided to join the company's Simple Retirement Account (IRA form) and has a few questions....
-
Three masses, weighing \(225 \mathrm{~g}, 320 \mathrm{~g}\), and \(550 \mathrm{~g}\), are attached around the rim, of diameter \(750 \mathrm{~mm}\), of a flywheel at the angular locations...
-
Review Problem for Chapters 1 and 2 Lift It, Inc., manufactures chain hoists. The raw materials inventories on hand on October 1 were as follows: Chain . . . . . . . . . . . . . . . . . . . . . . . ....
-
14. Again two forces are applied to the cart with two different spring scales as shown below. The spring scale FA still reads 10.5 N. FB FA The cart moves with a constant velocity toward the right....
-
The Shop at Home Network sells various household goods during live television broadcasts. The company owns several warehouses to hold many of the goods it sells, but also leases extra warehouse space...
-
The following data resulted from an experiment to compare three burners, B1, B2, B3. A Latin square design was used as the tests were made on three engines and were spread over three days. Engine 1...
-
Design Hilbert transformers of orders \(M=38,68\), and 98 using a Type IV structure and the Hamming window method.
-
Given a lowpass FIR filter with transfer function \(H(z)\), describe what happens to the filter frequency response when: (a) \(z\) is replaced by \(-z\). (b) \(z\) is replaced by \(z^{-1}\). (c)...
-
Show that the autocorrelation method yields an AR system whose poles are not outside the unit circle in the \(z\) plane.
-
Suppose you just received a shipment of nine televisions. Three of the televisions are defective. If two televisions are randomly selected, compute the probability that both televisions work. What is...
-
This past semester, a professor had a small business calculus section. The students in the class were Jinita, William, Al, Allison, Pam, Mike, Neta, and Jim. Suppose the professor randomly selects...
-
From the information in these charts, calculate the cost of equity, ROA, and WACC for each capital structure: 30%, 50%, and 70%. Based on following formulas: WACC = RA=XRE+XRD ( (1-Tc) R = Ru + (Ru ...
-
A test car is driven a fixed distance of n miles along a straight highway. (Here n Z+.) The car travels at one mile per hour for the first mile, two miles per hour for the second mile, four miles...
-
Define each of the following terms: a. Determinant b. Functional dependency c. Transitive dependency d. Recursive foreign key e. Normalization f. Composite key g. Relation h. Normal form i. Partial...
-
For each order, list the order ID, customer ID, order date, and most recent date among all orders. Show how you constructed this query using a Venn diagram.
-
Visit www.kimballgroup.comand locate Kimball University Design Tip 37. Study this design tip and draw the dimensional model for the recommended design for a "pipeline" application for university...
-
S1 Ltd and S2 Ltd belong to the same capital gains group. In May 2020, S1 Ltd transferred a chargeable asset to S2 Ltd. The original cost of this asset to S1 Ltd was 10,000 and its market value in...
-
The ordinary share capital of W Ltd (which is a trading company) is owned 30% by X Ltd, 25% by Y Ltd and 45% by Z Ltd. All of these companies are UK resident and they prepare accounts to 31 March....
-
E Ltd has taxable total profits of 800,000 for the year to 31 March 2024 and receives no dividends. For many years, the company has owned 65% of the ordinary shares of F Ltd and 30% of the ordinary...
Study smarter with the SolutionInn App