Question: 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

1 Expert Approved Answer
Step: 1 Unlock

Heres a Java program that implements a stack using both an array and ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!