Reputation: 1075
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
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