GeekInterview.com
Series: Subject: Topic:
Question: 53 of 249

Double Linked List

Make a middle node of doubly link list to the top of the list.
Asked by: shivi10j | Member Since Mar-2009 | Asked on: Jun 18th, 2009

View all questions by shivi10j

Showing Answers 1 - 3 of 3 Answers
ravi6771

Answered On : Aug 12th, 2009

View all answers by ravi6771

Let suppose x is the node to be moved to topx->next->prev=x->prev;x->prev->next=x->prev->next->next;x->next=head;head->prev=x;head=x;

  
Login to rate this answer.
f2003062

Answered On : Aug 19th, 2009

View all answers by f2003062

Lets say if the middle node of the doubly linked list is "middle" and the start node is "head".then the code as follows.middle->prev->next = middle->next;middle->next->prev = middle->prev;// Now make the middle as head.middle->prev = NULL;middle->next = head;head->prev = middle;head = middle;

Yes  1 User has rated as useful.
  
Login to rate this answer.
kronos

Answered On : Nov 16th, 2009

View all answers by kronos

Node *n1,*n2;n1 = n2 = head;while((n2->next) && (n2->next->next)){     n1 = n1->next;     n2 = n2->next->next;]// n1 points to the middle nown1->prev->next = n1->next;n1->next->prev = n1->prev;n1 ->prev = head ->prev; //NULL generally, non NULL value if circular list.n1 ->next = head;head = n1;

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.