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
why is iostream::eof inside a loop condition considered wrong?
What is c++ and its features?
What are default parameters? How are they evaluated in c++ function?
What are the important differences between c++ and java?
What is a buffer c++?
What is extern c++?
What is the oldest programming language?
What are c++ templates used for?
How does c++ sort work?
What's the best free c++ profiler for windows?
What is the difference between #define debug 0 and #undef debug?
What is a tree in c++?
Can c++ be faster than c?
What is a pdb file?
What are the various access specifiers in c++?