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 is the hardest coding language to learn?
What is buffering in c++?
What is an overflow error?
What language does google use?
What is polymorphism & list its types in c++?
If you push the numbers (in order) 1, 3, and 5 onto a stack, which pops out first a) 1 b) 5 c) 3
an integer constant must have atleast one a) character b) digit c) decimal point
What is the basic concept of c++?
What are multiple inheritances (virtual inheritance)? What are its advantages and disadvantages?
How are Structure passing and returning implemented by the compiler?
What is token c++?
What is a float in c++?
What are references in c++?
True or false, if you keep incrementing a variable, it will become negative a) True b) False c) It depends
What flag means?