DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2002
    Posts
    1

    Exclamation 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!!!

  2. #2
    Join Date
    Jul 2002
    Posts
    26
    If all the items in the list are going to be of the same type (in this case they look like Integers), you can use the sort method on Collections to sort them once you have put them into you LinkedList object. Remember when inserting the ints into your LinkedList you must add them as Integers and not ints. Once you have the list populated you can just call Collections.sort( list ), where list is your LinkedList.

    -gc

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links