Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 difference between path and classpath variables?

1154


What is string [] args?

1062


Is hashmap thread safe?

1058


What is replaceall in java?

1081


Why for each loop is used?

1067


Explain the difference between jdk, jre, and jvm?

1083


What is boolean flag in java?

1155


Can main() method in java can return any data?

1241


Why object class is super class for every class in java?

1084


Which class represents the socket that both the client and server use to communicate with each other?

1087


What is the constructor?

1101


How are java objects passed to a method and what are native methods?

1127


Which class is used by server applications to obtain a port and listen for client requests?

1020


what is the purpose of the runtime class?

1107


Explain list interface?

998