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
Explain the transient field modifier?
What is meant by class?
What is a method signature java?
Is there a sort function in java?
Why main() method is public, static and void in java ?
What is difference between module and function?
What are new features introduced with java 8 ?
In which order the iterator iterates over collection?
What is the lifetime and scope of a variable?
Can you make a constructor final?
How do you compare two strings lexicographically?
What is the difference between overriding & overloading?
What is the purpose of a volatile variable?
What is a parameter in a function?
Can abstract class have private constructor?