Hello, I've been having problem with understanding merge sort for linked list. I understood merge sort for array though, I think. I've googled it and all I can find are codes. I need to understand the algorithm first before I can understand the code.
Please help me understand merge sort for linked list.
So in array, you copy the elements of the supposed-to-be-sorted-array to another array then through recursion, logically divide the elements until there are two elements left (I think you'll just move the pointers through recursion). Then sort the divided halves.
Illustration:
Divide
7 5 1 0 29 2 12
7 5 1 0 | 29 2 12
7 5 | 1 0 | 29 2 | 12
and Conquer
5 7 | 0 1 | 2 29 | 12
0 1 5 7 | 2 12 29
0 1 2 5 7 12 29
Am I correct?? I only want to verify.. Please answer.
So in link list, am I supposed to follow the same idea?
Should I just move the pointers at the middle of list and repeat until there are two elements left? Then sort it?
Please answer.