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
Which operator cannot overload?
What is the size of a vector?
How do you invoke a base member function from a derived class in which you’ve overridden that function?
When does the c++ compiler create temporary variables?
What is the difference between global variables and static varables?
What is abstract keyword in c++?
What is operator overloading in c++ example?
What is the use of typedef?
Which should be more useful: the protected and public virtuals?
Where is atoi defined?
What is auto type c++?
What is #include math h in c++?
What are the advantages of using typedef in a program?
What are shallow and deep copy?
which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?