[algogeeks] Re: merge two sorted list

2012-02-24 Thread Don
You're right. I needed tail = tail-next; Before the closing } of the while loop. Good catch. Don On Feb 23, 10:25 pm, Ashish Goel ashg...@gmail.com wrote: tails needs to be updated in while loop also Best Regards Ashish Goel Think positive and find fuel in failure +919985813081

Re: [algogeeks] Re: merge two sorted list

2012-02-24 Thread atul anand
minute error : tail should be *tail while initializing instead of tail. now it will work fine. On Fri, Feb 24, 2012 at 7:55 PM, Don dondod...@gmail.com wrote: You're right. I needed tail = tail-next; Before the closing } of the while loop. Good catch. Don On Feb 23, 10:25 pm, Ashish

[algogeeks] Re: merge two sorted list

2012-02-24 Thread Gene
Ah, this reminds me of a beautiful thing that a fine gentleman CB Falconer posted once in comp.programmer. It was so elegant that my normally bad memory still remembers it after some years. You can simplify the merge by using a dummy node for the head of the merged list rather than just a

[algogeeks] Re: merge two sorted list

2012-02-23 Thread Don
Why are you using tail recursion when an iterative approach would be more efficient? Don On Feb 23, 3:41 am, rahul sharma rahul23111...@gmail.com wrote: struct node* SortedMerge(struct node* a, struct node* b) {   struct node* result = NULL;   /* Base cases */   if (a == NULL)      

[algogeeks] Re: merge two sorted list

2012-02-23 Thread Don
// Iterative merge struct node* SortedMerge(struct node* a, struct node* b) { struct node* head, tail; // Select first node if (a-data b-data) { head = tail = a; a = a-next; } else { head = tail = b; b = b-next; } // Merge lists while(a b) { if (a-data

[algogeeks] Re: merge two sorted list

2012-02-23 Thread Don
Is the desired behavior to remove duplicates? On Feb 23, 5:14 am, Karthikeyan V.B kartmu...@gmail.com wrote: Hi, this logic generates 10 10 20 25 .. and so on it doesn delete the duplicates in the result list -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Re: merge two sorted list

2012-02-23 Thread Ashish Goel
tails needs to be updated in while loop also Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Thu, Feb 23, 2012 at 8:19 PM, Don dondod...@gmail.com wrote: // Iterative merge struct node* SortedMerge(struct node* a, struct node* b) { struct