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


Please Help Members By Posting Answers For Below Questions

What is the use of data hiding?

582


What is abstraction in c++?

664


Will the following program execute?

545


Explain the difference between struct and class in terms of access modifier.

681


How to allocate memory dynamically for a reference?

532






Explain the difference between class and struct in c++?

579


How long will it take to learn programming?

572


What is a rooted hierarchy?

669


What are c++ templates used for?

600


Which ide is best for c++?

529


Can a program run without main in c++?

571


Describe exception handling concept with an example?

544


what is pre-processor in C++?

581


How do you invoke a base member function from a derived class in which you have not overridden that function?

570


What is the size of a vector?

559