gatsbyz
gatsbyz

Reputation: 1075

Sorting numbers as I get them dynamically from a stream

What algorithm should I use to sort numbers (in an array) as I get the numbers from a stream dynamically?

Should I just create a Hash, then merge sort?

Upvotes: -1

Views: 86

Answers (1)

Armand Chocron
Armand Chocron

Reputation: 149

If you need the array to be sorted continually, you should use Insertion-Sort algorithm each time a number is entered. Check the Wikipedia page for more information. If not, you can just receive all the numbers from the input and perform, once you received all the numbers, merge sort, as you suggested.

Upvotes: 1

Related Questions