Answer Posted / kaustubh
I'll give the algo here.You may write it in a programming
language of your choice.
Iterative Algo:
node *Reverse(node *head)
{
node *p,*q,*r;
p=head;q=r=NULL;
while(p!=NULL)
{
q=p;
p=p->next;
q->next=r;
r=q;
}
head=q;
return head;
}
Recursive algo:
From main call: Reverse(node *head,NULL)
reverse(node *p,node *q)
{
if(p->next!=NULL)
reverse(p->next,p)
else
{
p->next=q;
return
}
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is java regex?
What is the difference between iterator and list iterator?
What is an example of a constant variable?
What is map and hashmap in java?
What is ordered map in java?
What's the access scope of protected access specifier?
Why synchronization is important?
What is a method header?
Explain why wait(), notify() and notifyall() methods are in object class rather than in thread class?
What is the base class for error and exception?
What are the kinds of polymorphism?
What are the drawbacks of reflection?
What is the indent key?
Can we create object of inner class in java?
How do I get 64 bit java?