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
What is the sequence of destruction of local objects?
What is a hash function c++?
What are single and multiple inheritances in c++?
What is the difference between ++ count and count ++?
What are the types of pointer?
What is the iunknown interface?
Given the following seqment of code containing a group of nested if instructions: y = 9; if ((x==3) || (x == 5)) y++; else if (x == 2) y *= 2; else if (x == ) y-= 7; else y = 8; if the value of x is 4 before the nested IFs are executed, what is the value of y after the nested IFs are executed?
Describe exception handling concept with an example?
How do you instruct your compiler to print the contents of the intermediate file showing the effects of the preprocessor?
Write a program which uses functions like strcmp(), strcpy()? etc
What happens when the extern "c" char func (char*,waste) executes?
What do you mean by function overriding & function overloading in c++?
How do you save a c++ program?
What is the error in the code below and how should it be corrected?
What is a constant? Explain with an example.