0
我一直在試圖弄清楚如何實現K方式合併以下算法。K方式合併排序陣列實現使用最小堆
Algorithm:
1)Initialize an array of size n*k.
2) Initialize a min heap of size k, to hold the smallest element of each array.
3) Add the smallest element from the minHeap into the output array.
4)Move the next element from the array from which the min element was derived onto the heap. // How would one implement this?
5) Repeat step 4 until all the arrays are empty and the minHeap is empty.
我已經能夠實現所有,但我的算法的第4步。如何跟蹤從中提取最小元素的數組?