Linked List reverese program

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


Please Help Members By Posting Answers For Below Questions

what is anonymous class in java?

544


What are the different types of multitasking?

657


What are the differences between abstract class and interface?

513


What is java Applet?

650


How can you share data between two thread in Java?

523






Is space a char?

533


What is a byte string?

622


What are alternatives to java serialization?

602


What is the difference between hashmap and hashtable? What is an interface?

506


What do you understand by access specifiers in Java?

586


Explain different forms of polymorphism?

654


What is a nonetype?

565


What is the purpose of the finally clause of a try-catch-finally statement in java programming?

511


How to declare objects of a class ?

588


Can constructor return value?

512