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
Do you know the problem with overriding functions?
How can I disable the "echo" feature?
Is rust better than c++?
What is virtual base class uses?
What is the object serialization?
Difference between overloaded functions and overridden functions
What is namespace & why it is used in c++?
Is nan a c++?
an operation between an integer and real always yeilds a) integer result b) real result c) float result
What is the best ide for c++?
Why cstdlib is used in c++?
Tell me can a pure virtual function have an implementation?
Where the memory to the static variables is allocated?
What is c++ code?
What are the manipulators in c++?