Re: [algogeeks] Amazon Interview Question about Linked Lists
@Saurabh You used an extra pointer compared to shiva's code ,you can avoid that. :) On Mon, Dec 20, 2010 at 8:24 PM, Saurabh Koar saurabhkoar...@gmail.comwrote: @Rishi:I think Shiva's code is also fine.U can access the list easily by using down pointer in his code. Because he is assigning temp-down=temp2 and then he is making temp-fwd=NULL. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thanks Regards Nikhil Agarwal Senior Undergraduate Computer Science Engineering, National Institute Of Technology, Durgapur,India http://tech-nikk.blogspot.com http://beta.freshersworld.com/communities/nitd -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon Interview Question about Linked Lists
@Nikhil: ya..rt -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon Interview Question about Linked Lists
See inline .. On Sat, Dec 18, 2010 at 12:09 PM, siva viknesh sivavikne...@gmail.comwrote: Given a linked list structure where every node represents a linked list and contains two pointers of its type: (i) pointer to next node in the main list. (ii) pointer to a linked list where this node is head. Write a C function to flatten the list into a single linked list. Eg. If the given linked list is 1 -- 5 -- 7 -- 10 | | | 2 6 8 | | 3 9 | 4 then convert it to 1 - 2 - 3 - 4 - 5 - 6 - 9 - 7 - 8 -10 My solution - not tested : struct node { int data; struct node *fwd; //pointer to next node in the main list. struct node *down; //pointer to a linked list where this node is head. }*head,*temp,*temp2; temp=head; while(temp-fwd!=NULL) { temp2=temp-fwd; while(temp-down!=NULL) { temp=temp-down; } temp-down=temp2; // how will the code access the flattened linked list by down or by fwd ? In this case there in no particular pointer by which the code can access the linked list. Try to write a function to print the flattened linked list. temp-fwd=NULL; temp=temp2; } plz notify me if anything...other solutions and optimizations are welcome -- Regards, $iva -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards, Rishi Agrawal -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon Interview Question about Linked Lists
temp=head; temp1=temp-fwd; while(temp-fwd!=NULL) { temp2=temp; while(temp2-down!=NULL) temp2=temp2-link; temp2-down=temp1; temp-fwd=NULL; temp=temp1; temp1=temp1-fwd; } U can print the linked list using down pointer.Hope this will work.Correct me if I m wrong. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon Interview Question about Linked Lists
@Rishi:I think Shiva's code is also fine.U can access the list easily by using down pointer in his code. Because he is assigning temp-down=temp2 and then he is making temp-fwd=NULL. On 12/20/10, Saurabh Koar saurabhkoar...@gmail.com wrote: temp=head; temp1=temp-fwd; while(temp-fwd!=NULL) { temp2=temp; while(temp2-down!=NULL) temp2=temp2-link; temp2-down=temp1; temp-fwd=NULL; temp=temp1; temp1=temp1-fwd; } U can print the linked list using down pointer.Hope this will work.Correct me if I m wrong. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon Interview Question about Linked Lists
@Rishi:I think Shiva's code is also fine.U can access the list easily by using down pointer in his code. Because he is assigning temp-down=temp2 and then he is making temp-fwd=NULL. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Amazon Interview Question about Linked Lists
Given a linked list structure where every node represents a linked list and contains two pointers of its type: (i) pointer to next node in the main list. (ii) pointer to a linked list where this node is head. Write a C function to flatten the list into a single linked list. Eg. If the given linked list is 1 -- 5 -- 7 -- 10 | | | 2 6 8 | | 3 9 | 4 then convert it to 1 - 2 - 3 - 4 - 5 - 6 - 9 - 7 - 8 -10 My solution - not tested : struct node { int data; struct node *fwd; //pointer to next node in the main list. struct node *down; //pointer to a linked list where this node is head. }*head,*temp,*temp2; temp=head; while(temp-fwd!=NULL) { temp2=temp-fwd; while(temp-down!=NULL) { temp=temp-down; } temp-down=temp2; temp-fwd=NULL; temp=temp2; } plz notify me if anything...other solutions and optimizations are welcome -- Regards, $iva -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.