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 the difference between a choice and a list?
When should the method invokelater() be used?
Define max and min heap, also the search time of heap.
What is the private method modifier?
Why do we use return statement?
Is hashset sorted in java?
Difference between class#getinstance() and new operator ?
What do you understand by final value?
What is threaded programming and when is it used? : Java thread
Can a constructor be protected?
What are keywords in programming?
What is a double vs float?
what is the significance of listiterator in java?
Can we use a default constructor of a class even if an explicit constructor is defined?
What is a pattern what is an anti pattern?