开发者

merge part in merge sort

开发者 https://www.devze.com 2023-01-05 00:47 出处:网络
we have merge sort for two arrays or linked list how can I write merge part for more than two l开发者_运维知识库inked lists?

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

精彩评论

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