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
why is iostream::eof inside a loop condition considered wrong?
What is called array?
Do vectors start at 0?
What is a modifier in c++?
Write about the use of the virtual destructor?
Name the implicit member functions of a class.
Can turbo c++ run c program?
What does ios :: app do in c++?
Difference between delete and free.
Explain deep copy?
What is time h in c++?
Differences between private, protected and public and give examples.
What are enumerations?
What are virtual functions in c++?
Is swift better than c++?