Linked List reverese program
Answers were Sorted based on User's Feedback
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 |
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 |
Distinguish method overloading and overriding
Instead of writing Home, Remote Interfaces if i directly extends EJBObject to bean class what happens?
What is an arraylist in java?
How do you get the length of a string in java?
what is the use of declaring constructor as private?
5 Answers Cyient, IVY Technologies, Sai Softech, Virtusa,
What are different types of references?
How do you input a string in java?
What are the characteristics of java?
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?
what is meant by string pooling?
12 Answers Oracle, Polaris, Tribal Fusion, Wipro,
What will happen when using pass by reference in java?
what is the use of private constructor in core java?
3 Answers OnMobile, Satyam, Yash Technologies,