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 OOP Language?
What is meant by object?
Why are constructors used?
What is slash r?
Why does java not support pointers?
Why is string builder not thread safe?
What is the largest long allowed by java?
Why put method is idempotent?
What are multiple inheritances? Is it supported by java?
What is the difference between a choice and a list?
What is final keyword in java?
What are the problems faced by java programmers who don't use layout managers?
How will you reverse a link list without using recursion?
How do you add an element to an arraylist in java?
Why do we need data structure in java?