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 compiler does turbo c++ use?
What is singleton pattern in c++?
int age=35; if(age>80) {Console.WriteLine("Boy you are old");} else {Console.WrieLine("That is a good age");}
Why ctype h is used in c++?
What do you mean by “this” pointer?
What is the difference between new() and malloc()?
Will a C compiler always compile C++ code a) Yes b) No c) Only optimized compilers
What is a constant reference?
What are the extraction and insertion operators in c++? Explain with examples.
What are the various operations performed on stack?
What is pointer -to-members in C++? Give their syntax?
Can a new be used in place of old mallocq? If yes, why?
Why do we need pointers?
What are the advantage of using register variables?
What is c++ prototype?