# Reverse a doubly circular linked list

The problem is to reverse the given doubly circular linked list.

Examples:
Input:

Output:

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Algorithm:

Declare last

new_node->next = new_node->prev = new_node
return

new_node->prev = last
last->next = new_node

Declare last

Initialize curr = last, prev

while curr->prev != last
prev = curr->prev
curr = prev

Explanation: The variable head in the parameter list of insertEnd() is pointer to a pointer variable. reverse() traverses the doubly circular linked list starting with head pointer in backward direction and one by one gets the node in the traversal. It inserts those nodes at the end of the list that starts with the new_head pointer with the help of the function insertEnd() and finally returns new_head.

## C#

Output:

Current list:
Forward direction: 1 2 3 4 5
Backward direction: 5 4 3 2 1

Reversed list:
Forward direction: 5 4 3 2 1
Backward direction: 1 2 3 4 5

Time Complexity: O(n).

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.