Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Write a program 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

Step: 1

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago