10
Mar
Reversing a circular single linked list using pointers
Related Blog Items
- Reversing single linked list recursively
- Reversing a single linked list using stack
- Reversing a double linked list
- Reverse linked list using pointers
- Circular Doubly Linked List With Out Using Special Head or Tail Node
Reversing a single linked list is explained in this post
this post deals with reversing circular single linked list, which is not much different from what we did there except the last reversed node points the head node, then we change the head node to point to reversed linked list….
You might be thinking why do we need to reverse a circular linked list when the list is circular, but as the list is single linked list here we are going to reverse the direction of the list.
here is the routine which reverses circular list….
typedef struct node Node;
void reverse(Node** headRef)
{
Node* result = NULL;
Node* current = *headRef;
Node* next;
while (current != NULL)
{
next = current->next; // tricky: note the next node
current->next = result; // move the node onto the result
result = current;
current = next;
if (current == *headRef)
{
//met the beginning node...
break;
}
}
(*headRef)->next = result;
*headRef = result;
}
please let me know your comments…..
Popularity: 58%
You need to log on to convert this article into PDF
Related Blog Items - Reversing single linked list recursively
- Reversing a single linked list using stack
- Reversing a double linked list
- Reverse linked list using pointers
- Circular Doubly Linked List With Out Using Special Head or Tail Node
Related Blog Items
- Reversing single linked list recursively
- Reversing a single linked list using stack
- Reversing a double linked list
- Reverse linked list using pointers
- Circular Doubly Linked List With Out Using Special Head or Tail Node
I’d liked your stuff, seems you are a pro programmer
January 22nd, 2008 at 11:05 pm