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

Write about the stack unwinding?

833


Explain the scope of resolution operator.

844


Why was c++ created?

781


Keyword mean in declaration?

790


Differentiate between declaration and definition.

776


Why is c++ so fast?

734


What are the characteristics of friend functions?

760


What is the best ide for c++?

794


What things would you remember while making an interface?

764


Explain this pointer?

775


Is c++ built on c?

762


When does the c++ compiler create temporary variables?

804


What is meant by const_cast?

859


Can the operator == be overloaded for comparing two arrays consisting of characters by using string comparison?

780


Define upcasting.

793