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 the meaning of course?

577


Mention a package that is used for linked list class in java.

522


What is java used for on a computer?

505


What is the importance of static variable?

584


Is java a super set of javascript?

577






Can you use this() and super() both in a constructor?

520


Why do we declare a class static?

537


Can a method be static?

520


What is keyword in oop?

512


What is the purpose of sizeof operator?

524


Explain the use of shift operator in java. Can you give some examples?

533


How do you create a null object?

506


Tell us something about an iterator.

544


How many functional interfaces does java 8 have?

598


What is a bubble sort in java?

541