开发者

merge part in merge sort

we have merge sort for two arrays or linked list how can I write merge part for more than two l开发者_运维知识库inked lists? please help me thanks


Either merge two at a time and merge the result with the third or alter the merging logic to take the min element from all three lists.


Recursively split the set of arrays up into two sets of arrays that need to be merged. When the set contains only one array return it. Merge the resulting list from each call using your standard merge sort.

 array merge( list_of_arrays )
 {
     if (sizeof(list_of_arrays) == 1)
        return list
     else
        return mergesort( merge( first_half( list_of_arrays ) ), merge( second_half( list_of_arrays ) ) )
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜