Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


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 ststic with example

0 Answers   Wipro,


How does JAVA ClassLoader work?

1 Answers   IBM,


Can we access private data outside of the class directly in java programming language? Why There is no runtime checking in java, which leads to access the private data directly outside of a class?

5 Answers   Google,


What is a "pure virtual" member function?

0 Answers   Amazon,


JVM is platform independent or depeneded?

7 Answers  






What about abstract classes in java?

0 Answers  


Describe what happens when an object is created in java ?

0 Answers  


how can u handle run time exception in java? explain with brief explanation with examples?

2 Answers   CTS,


Implement a stack with push (), pop() and min() in O(1) time.

0 Answers   Amazon,


Convert Binary tree to linked list.

0 Answers   Amazon,


Write a program to show whether a graph is a tree or not using adjacency matrix.

0 Answers   Amazon,


how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? Or extending thread class or implementing runnable interface. Which is better? : Java thread

0 Answers  






Categories