Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write A JAVA PROGRAM FOR THE FOLLOWING QUESTION Note: U are not allowed to use inbuilt stack or any other features. U should create

Write A JAVA PROGRAM FOR THE FOLLOWING QUESTION Note: U are not allowed to use inbuilt stack or any other Input - Output Format The input consists of multiple lines, each one containing either one or two integers. 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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Heres a Java program that implements a stack using both an array and ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Programming questions

Question

Show that if A is any m n matrix, then Im A = A and AIn = A.

Answered: 1 week ago