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 is the difference between function overloading and operator overloading?
What is java and c++?
What is implicit pointer in c++?
Differentiate between the manipulator and setf( ) function?
Explain the difference between c & c++?
Function can be overloaded based on the parameter which is a value or a reference. Explain if the statement is true.
what does the following statement mean? int (*a)[4]
Describe Trees using C++ with an example.
Why c++ is created?
What is class definition in c++ ?
How do you define a class in c++?
What's c++ used for?
Is java easier than c++?
What is runtime polymorphism in c++?
True or false, if you keep incrementing a variable, it will become negative a) True b) False c) It depends