views:

29

answers:

2

Hi we have merge sort for two arrays or linked list how can I write merge part for more than two linked lists? please help me thanks

A: 

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.

btreat
A: 

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 ) ) )
 }
tvanfosson
what will happen to the temporary memory?
@matin - not sure what you mean. The only appreciable extra memory is in the standard mergesort, otherwise you're just breaking down which arrays that you're working with to merge.
tvanfosson