Reverse Double Linked List

Given a double linked list's head node, reverse the list and return the new head node.

Java Solution

/*
    * For your reference:
    *
    * DoublyLinkedListNode {
    *     int data;
    *     DoublyLinkedListNode next;
    *     DoublyLinkedListNode prev;
    * }
    *
    */
static DoublyLinkedListNode reverse(DoublyLinkedListNode head) {
    DoublyLinkedListNode p = head;
    DoublyLinkedListNode newHead = head;
 
    while(p!=null){
        DoublyLinkedListNode t = p.next;
        p.next = p.prev;
        p.prev = t;
 
        newHead= p;
        p = t;
    }
 
    return newHead;
}
Category >> Algorithms  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code> 
String foo = "bar";
</code></pre>