@Atul: after u sort the list the head pointer will automatically point to
the smallest element so u actually return the head of the list.
@Sambhavna:
here is the Pseudoccode (More or less similar to, doing merge sort for
arrays):
Mersgesort(node ** list){
if( head==NULL or head-> next == NULL) return;
//split the list into 2 halves (lets say *a and *b)
split(list, a , b);
//sort the two halves individually
mergesort(a);
mergesort(b);
//merge the two halves and return the smallest (first) element
*head = sortedMerge(a,b);
}
for merging u can use recursion:
Merge(node *a, node *b){
struct node *temp;
if (a== NULL ) return b;
if(b==NULL) return a;
if(a-> data <= b-> data)
temp = a;
temp-> next = Merge(a->next, b);
else
temp = b;
temp-> next = Merge(a, b-> next);
return;
}
On Sat, Mar 24, 2012 at 1:55 PM, Sambhavna Singh <[email protected]>wrote:
> can anyone explain vividly how we can use merge sort here. thank you.
>
>
> On Sat, Mar 24, 2012 at 1:54 PM, Sambhavna Singh
> <[email protected]>wrote:
>
>> @atul: we always need to point at the next larger node..so that is ruled
>> out.
>>
>> On Sat, Mar 24, 2012 at 10:14 AM, Atul Singh <[email protected]>wrote:
>>
>>> I couldn't understand the meaning of " *return the pointer to smallest*
>>> "
>>> Is it that that the pointer of largest node will point to smallest node.
>>>
>>>
>>>
>>> ATul Singh | Final Year | Computer Science & Engineering | NIT
>>> Jalandhar | 9530739855 |
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.