Merge sort on array can be easily done due to it is easy to find the specific data in
a any given position index value. While, if it were the case in the linkedlist, it would
be tough to implemente the mergesort efficienty.
Thanks to the post,
I found the following source code in the Linux 2.6
The above code will merge two linked list. One extra struct *tail is being used to help construct the new linked list.
The above code deals with the merge sort, which is really tricky and amazing.
The key idea is in the
This part will store the partial lists, whose lengths whill be
where is the index of the part array.
It uses the Fibonacci
property of the length in the mergesort list. Only the same length list of occur
in the same specific position, and two same length lists will merge to a single list
whose length will double while the index in the part array is just the next postion.
At last, just merge all the elements in the part array, then the final list is constructed!