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
What do you mean by friend class & friend function in c++?
What is the basic structure of c++ program?
What is the error in the code below and how should it be corrected?
Is c++ a good beginners programming language?
How does c++ sort work?
Explain how the virtual base class is different from the conventional base classes of the opps.
What do c++ programmers do?
How we can differentiate between a pre and post increment operators during overloading?
Define virtual constructor.
What you know about structures in C++?
What is the use of cmath in c++?
What is the latest version on c++?
What is using namespace std in c++?
What character terminates all character array strings a) b) . c) END
Why do we use the using declaration?