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
Is it necessary that each try block must be followed by a catch block?
How do you define a variable?
What is starvation?
What languages are pass by reference?
What is the difference between this() and super() in java?
Why unicode is important?
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? : Java thread
Can you extend main method in java?
what is the purpose of the wait(), notify(), and notifyall() methods? : Java thread
Can a final variable be null?
What is the difference between notify and notifyall method?
How many arguments can a method have java?
Explain the inheritance?
What is a treeset in java?
What occurs when an object is constructed?