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

Distinguish method overloading and overriding

2 Answers   Tech Mahindra,


Instead of writing Home, Remote Interfaces if i directly extends EJBObject to bean class what happens?

1 Answers   Flextronics,


What is an arraylist in java?

0 Answers  


How do you get the length of a string in java?

0 Answers  


what is the use of declaring constructor as private?

5 Answers   Cyient, IVY Technologies, Sai Softech, Virtusa,


What are different types of references?

0 Answers  


How do you input a string in java?

0 Answers  


What are the characteristics of java?

0 Answers  


I want my class to be developed in such a way that no other class (even derived class) can create its objects. Define how can I do so?

0 Answers  


what is meant by string pooling?

12 Answers   Oracle, Polaris, Tribal Fusion, Wipro,


What will happen when using pass by reference in java?

0 Answers   HCL,


what is the use of private constructor in core java?

3 Answers   OnMobile, Satyam, Yash Technologies,


Categories