Program Reversing a linked list

Write Program to Reversing a linked list
void Reverse(struct node** headRef) {
struct node* result = NULL;
struct node* current = *headRef;
struct 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;
*headRef = result;
}
}

0 comments:

Post a Comment