|
-
Nov 19th, 2002, 04:25 AM
#1
Thread Starter
Banned
Urgent. Please Help.
Hi.
I need to write a program to sort data from .dat file. The following is how the data in the file looks like:
5
7
2
13
11
It is required to pass each above as an object to a "SortItem"method, such like:
public void SortItem (Object o) {
// Use linked list and compareTo to sort the object.
}
The object is successfully passed, but the main problem is that I don't know how to use linked list to sort it. Would you show me
how to do it? Or give me an example?
Thanks a lot!!!
-
Nov 19th, 2002, 08:32 AM
#2
java.util.Collections.sort(List list [, Comparator c]);
Sorts the list in ascending order, either with natural ordering (<) or via the Comparator object.
Usage:
Code:
import java.util.*;
// ...
List l = new LinkedList();
int i = readFromFile();
l.add(i);
// repeat until file is completly read
Collections.sort(l);
// l is now sorted. Given the input in your
// post it would now contain (2,5,7,11,13)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|