<p>How to creat linked list and print out the list in <p>sorted order.
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rafal_Szymanski
Posted On:   Tuesday, April 16, 2002 04:19 PM

			


My question is how to creat linked list and print out

the list in sorted order.I want to creat list ttat

contains Name age and salary .

Example:

Jones C. 22 27000.00

How i should start!

Re: <p>How to creat linked list and print out the list in <p>sorted order.

Posted By:   Thomas_Foertsch  
Posted On:   Thursday, April 18, 2002 12:19 AM


There's a util class for Collections since JDK 1.2 - java.util.Collections.




List list = new LinkedList();


list.add("b");

list.add("a");

list.add("c");


Collections.sort(list);


Re: <p>How to creat linked list and print out the list in <p>sorted order.

Posted By:   John_Smith  
Posted On:   Tuesday, April 16, 2002 10:58 PM


Create a class Employee implementing Comparable with name, age, salary and a toString() method to print all of the values at once.



Create a new class EmployeeList with a TreeSet of employees and in its main method:


  1. Add each Employee to employees.
  2. Grab the employees iterator and print each of the employees.


Generally linked lists aren't used all that much in Java. If you wanted to link the nodes, you could put a nextEmployee field in Employee and link that to the next employee when you iterate through.

About | Sitemap | Contact