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
Write about the stack unwinding?
Explain the scope of resolution operator.
Why was c++ created?
Keyword mean in declaration?
Differentiate between declaration and definition.
Why is c++ so fast?
What are the characteristics of friend functions?
What is the best ide for c++?
What things would you remember while making an interface?
Explain this pointer?
Is c++ built on c?
When does the c++ compiler create temporary variables?
What is meant by const_cast?
Can the operator == be overloaded for comparing two arrays consisting of characters by using string comparison?
Define upcasting.