Reversing a Doubly Linked List

 Here's a quick code to reverse a Doubly linked list

void reverse(Node* head)

{

    Node* temp= NULL;

    Node* current=head;

    while(current!=NULL)

        temp=current->prev;

        current->prev=current->next;

        current->next=temp;

        current=current->prev;

    if(temp!=NULL)

            head= temp->prev;

}


Popular posts from this blog

Finding the Subarrays (Hackerearth)

Palindrome Index (Hackerrank)

Sherlock and Array (Hackerrank)