Slick Slick - 1 year ago 40
Java Question

how to input n numbers and print it in ascending order without using array

I was trying to create a program that takes

number of input in a loop and capable of showing output in ascending order. The main theme of program is it should not use arrays.

I tried it by creating a program that takes input and shows smallest number first then 2nd smallest and 3rd smallest and so on. But I am new to programming so my program could do only like 1st smallest and it does not work.

I also saw heap data structure in one of the similar questions but couldn't figure out how it can work without arrays.

Please help me how can we use heap data structure or give me a good suggestion to do it.

Answer Source

You could use Streams:
            Spliterators.spliteratorUnknownSize(new Scanner(, Spliterator.ORDERED),