I have some short arrays that have been sorted. then I want to merge them into one large arrays and required to keep order. so how to implement that in fastest time and simplest complexity.
for example, I have three short array:
- 1 2 3 5 9
- 4 6 8 10 11
- 7 12 15 20 21
the merge result is: 1 2 3 4 5 6 7 8 9 10 11 12 15 20 21
of course, above example is so simple. In fact, my final result could be one millon integers together, may be some simple algorithm can be apply to work, such as bubble sort, quick sort, or heap sort etc, but I wanna the best effective algorithm to do it. can you give some resolution or good suggestion?
Thanks all for your answers below this question. I am just writing some routine for testing. I will use insert sorting algorithm and comparied to STL quick sort which is used in my older version project, so I want to see which's more fast?
In my opinion, insert sort will enhance the processing because of pre-sorting character of all the short arrays. I need to insert other short arrays into the first short array one by one. Another more helpful thing is that the first element of every other short arrays can tell you the base insert position after first vistor, so avoid to visit whole arry when deal with later element. Can you understand what I am talking? you guys, wait for my testing result. Thanks!