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 you know about c++?
Is sorted c++?
Explain the differences between list x; & list x();.
What is the best book for c++ beginners?
If a base class declares a function to be virtual, and a derived class does not use the term virtual when overriding that class, is it still virtual when inherited by a third-generation class?
Why is main an int?
What is auto used for in c++?
Is main a class in c++?
What is the c++ code?
What are virtual functions in c++?
What are files in c++?
What is pointer to member?
Write a program using display() function which takes two arguments.
Is map thread safe c++?
What is lambda expression c++?