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
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 .
Explain terminate() and unexpected() function?
Differentiate between late binding and early binding. What are the advantages of early binding?
How can a struct in c++ differs from a struct in c?
What are the advantages of using const reference arguments in a function?
What is the difference between C and CPP?
What is switch case in c++ syntax?
What are the differences between java and c++?
What is the best ide for c++?
What is setiosflags c++?
what is C++ objects?
When should we use multiple inheritance?
List the features of oops in c++?
Explain linear search.
When can I use a forward declaration?