Reverse a doubly linked list solution

Reverse a doubly linked list solution


Problem Statement

You’re given the pointer to the head node of a doubly linked list. Reverse the order of the nodes in the list. The head node might be NULL to indicate that the list is empty.

Source Code:

 /*  
   Reverse a doubly linked list, input list may also be empty  
   Node is defined as  
   struct Node  
   {  
    int data;  
    Node *next;  
    Node *prev;  
   }  
 */  
 Node* Reverse(Node* head)  
 {  
   Node *cur = head,*temp = new Node;  
   // Complete this function  
   // Do not write the main method.   
   while(cur !=NULL){  
     temp->next = cur->next;  
     temp->prev = cur->prev;  
     cur->next = temp->prev;  
     cur->prev = temp->next;  
     cur = temp->next;  
     if(cur!=NULL){  
       head = cur;  
     }  
   }  
   return head;  
 }  

9 comments :

  1. Our writing service is dedicating the excellent writing process and programs in online. The high volume of writing is possible in our writing service. You can manage your writing papers by the experts. The learning guide to be provide for the experts to the students.The essay writing service is available in our writing service

    ReplyDelete
  2. I want to check the whole tutorial now. Will you help me with that, friend?

    ReplyDelete

  3. I really appreciate this great post that you have provided us. I guarantee this will benefit most people and myself. thank you very much!


    Xvideostudio video editor apk
    twitch dark mode
    How many centimeters in a meter
    gogoanime

    ReplyDelete
  4. Casino - Dr.Mcd
    The main part 광주광역 출장안마 of the casino complex is the casino floor. The 제주 출장마사지 casino floor 부산광역 출장샵 is 부산광역 출장안마 expansive, filled with slots, live 제천 출장마사지 games, and poker. The  Rating: 3.4 · ‎1,722 reviews

    ReplyDelete