Which of the sorting algorithms heap-sort, quick-sort & merge-sort could work with a continuous stream of data? I want to have a list that's always sorted, so that new values can get into the list at the right location right away. I can't seem to find the specifics of always maintaining a sorted list and having a continuous data stream.
class StreamSorter<A extends Comparable <A>> {
// A[] sorted_list;
// other fields and initialiser: TODO
public void add_new_element(A x) {
// add new element to the data received so far and create a sorted list.
}
}
How would this class be implemented, so that everytime add_new_element is called, the sorted_list contains all the sorted elements so far?
Sorry if this is a stupid question, believe me, I've looked as hard as I can.
Cheers