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

Answers were Sorted based on User's Feedback



Linked List reverese program..

Answer / dsr

import java.util.Collections;
import java.util.LinkedList;


public class LikedListDemo {
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.add("Raju");
list.add("Gopal");
list.add("Senthil");
list.add("nagesh");
System.out.println("list size....."+list.size());
System.out.println("list ....."+list);
Collections.reverse(list);
System.out.println("revese list ....."+list);
}
}

Is This Answer Correct ?    8 Yes 3 No

Linked List reverese program..

Answer / 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

More Core Java Interview Questions

What is java string pool?

0 Answers  


Can extern variables be initialized?

0 Answers  


Can we have 2 main methods in java class?

0 Answers  


In C we use only compiler. Why java uses both compiler and interpreter? What is its significance?

5 Answers  


what are depricated methods ?

5 Answers   Satyam,


What is length in java?

0 Answers  


Whats the difference between notify() and notifyall()?

0 Answers  


What is array class in java?

0 Answers  


How can you generate random numbers in java?

0 Answers  


Describe the process as to how substring() methodology mechanisms in java.

0 Answers  


Explain pass by reference and pass by value?

8 Answers   IBM, Wipro,


diff. b/w JAVA and javascript...

3 Answers   NIIT,


Categories