Question: Write a program in java that sorts a stack of integers in descending order with the smallest item on top. You are allowed to use

Write a program in java that sorts a stack of integers in descending order with the smallest item on top. You are allowed to use one stack to hold your data and another stack as an auxiliary data structure. You may not use any other data structures such as array etc. to help you solve the problem. Hint You have push(), pop(), top() and isEmpty() methods to help you solve the problem. Input This program does not need to input any data from the console, instead you create a random number between 0 to 20 and then this number shows you the number of randoms that you should generate as your inputs. Inputs should be between 0 to 50. For example, if the first random number generated is 10, you need to generated 10 more random numbers and push them into the stack for sorting purpose. Output You first print the content of the stack and then print the sorted item. e.g. Random Number = 13 Initial Stack: [4, 7, 18, 39, 42, 8, 35, 23, 50, 0, 23, 11, 6] Sorted Stack: [0, 4, 6, 7, 8, 11, 18, 23, 23, 35, 39, 42, 50]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!