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 difference between path and classpath variables?
What is string [] args?
Is hashmap thread safe?
What is replaceall in java?
Why for each loop is used?
Explain the difference between jdk, jre, and jvm?
What is boolean flag in java?
Can main() method in java can return any data?
Why object class is super class for every class in java?
Which class represents the socket that both the client and server use to communicate with each other?
What is the constructor?
How are java objects passed to a method and what are native methods?
Which class is used by server applications to obtain a port and listen for client requests?
what is the purpose of the runtime class?
Explain list interface?