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

Write a Program for dynamically intialize a 2 dimentional array. Eg:5x20, accept strings and check for vowels and display the no.finally free the space allocated .

793


Explain terminate() and unexpected() function?

700


Differentiate between late binding and early binding. What are the advantages of early binding?

676


How can a struct in c++ differs from a struct in c?

702


What are the advantages of using const reference arguments in a function?

706






What is the difference between C and CPP?

719


What is switch case in c++ syntax?

712


What are the differences between java and c++?

609


What is the best ide for c++?

674


What is setiosflags c++?

621


what is C++ objects?

772


When should we use multiple inheritance?

700


List the features of oops in c++?

664


Explain linear search.

715


When can I use a forward declaration?

707