[algogeeks] Re: How to merge two unsorted single linked list to get a sorted list

2006-05-24 Thread varun_dale
I agree with Googmeister since in arrays the size of arrays are fixed we can't play wiht htem as easily as we can do with linked list. That's why we need to copy elements to another place when Merge sort is applied to arrays. But in linked list simle linking and de-linking saves that extra space r

[algogeeks] Re: How to merge two unsorted single linked list to get a sorted list

2006-05-24 Thread Googmeister
ashish wrote: > If you have memory to spare, then you can just copy the linked list to > an array and just do mergesort/radixsort etc. to get O(n logn) time > complexity. You don't need the extra memory - the beauty of mergesort on linked lists is that it can be done in-place, stably, and in O(

[algogeeks] Re: How to merge two unsorted single linked list to get a sorted list

2006-05-24 Thread ashish
This problem is no different from sorting a single linked list as two unsorted linked lists are essentially equivalent to one unsorted linked list by joining their ends. So just joining the two linked lists and sorting them will work. If you don't want to copy the information to an array i.e. spa