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 use of data hiding?
What is abstraction in c++?
Will the following program execute?
Explain the difference between struct and class in terms of access modifier.
How to allocate memory dynamically for a reference?
Explain the difference between class and struct in c++?
How long will it take to learn programming?
What is a rooted hierarchy?
What are c++ templates used for?
Which ide is best for c++?
Can a program run without main in c++?
Describe exception handling concept with an example?
what is pre-processor in C++?
How do you invoke a base member function from a derived class in which you have not overridden that function?
What is the size of a vector?