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;  
 }  

8 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