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

why is iostream::eof inside a loop condition considered wrong?

812


What is called array?

803


Do vectors start at 0?

756


What is a modifier in c++?

848


Write about the use of the virtual destructor?

786


Name the implicit member functions of a class.

827


Can turbo c++ run c program?

826


What does ios :: app do in c++?

773


Difference between delete and free.

823


Explain deep copy?

796


What is time h in c++?

856


Differences between private, protected and public and give examples.

764


What are enumerations?

854


What are virtual functions in c++?

895


Is swift better than c++?

726