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
What are friend classes? What are advantages of using friend classes?
What is extern c++?
Incase of a function declaration, what is extern means?
Why do we use templates?
What is == in programming?
Is there structure in c++?
What is class invariant in c++?
When should we use multiple inheritance?
Write a corrected statement in c++ so that the statement will work properly. if (4 < x < 11) y=2*x;
Does there exist any other function which can be used to convert an integer or a float to a string?
describe private access specifiers?
What is virtual destructor ans explain its use?
What is the full form nasa?
What are the defining traits of an object-oriented language?
What is meant by a delegate?