How many pointers are required to reverse a link list?
Answer Posted / patrick
You cannot must have a pointer to a pointer if you want to
modify the pointer.
void reverse(node** head)
{
node* cur = *head;
*head = null;
while (cur)
{
node* next = cur->next;
cur->next = *head;
*head = cur;
cur = next;
}
}
Besides the head pointer, you will need two local pointers.
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
Is there a sort function in c++?
Is c++ a pure oop language?
What is a map in c++?
What are the effects after calling the delete this operator ?
Which is better c++ or java?
What is abstract class in c++?
what is the use of void main() in C++ language?
find the two largest values among the 6 numbers using control structures : do-while,for,if else,nestedif- else ,while. one or two of them.
What are the 3 levels of programming languages?
What is a Default constructor?
Where is atoi defined?
List the types of polymorphism in c++?
What is the use of "new" operator?
Can turbo c++ run c program?
What is c++ namespace?