How many pointers are required to reverse a link list?

Answer Posted / prits

Using 3 pointers:
curr, next, result pointers, curr points to current node,
next obviously points to the next node, result points to
the new reversed linked list

void reverse_single_linked_list(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;
}

Is This Answer Correct ?    14 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the hardest coding language to learn?

592


What is buffering in c++?

578


What is an overflow error?

610


What language does google use?

582


What is polymorphism & list its types in c++?

608






If you push the numbers (in order) 1, 3, and 5 onto a stack, which pops out first a) 1 b) 5 c) 3

824


an integer constant must have atleast one a) character b) digit c) decimal point

547


What is the basic concept of c++?

568


What are multiple inheritances (virtual inheritance)? What are its advantages and disadvantages?

556


How are Structure passing and returning implemented by the compiler?

591


What is token c++?

568


What is a float in c++?

537


What are references in c++?

644


True or false, if you keep incrementing a variable, it will become negative a) True b) False c) It depends

1845


What flag means?

518