aspose file tools*
The moose likes Java in General and the fly likes linked list problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "linked list problem " Watch "linked list problem " New topic
Author

linked list problem

Pepo moussa
Ranch Hand

Joined: Mar 20, 2008
Posts: 36
well i got a problem in my program,i should write a method that will sort a linked list, the list contain class rooms example ("building name","room number",capacity), the sorting should be by room capacity ..so anyone have idea how this method, if anyone can show me a code or basic algorithm for this method that would be great thank you
[ April 03, 2008: Message edited by: I moussa ]
Alberto Caraz
Greenhorn

Joined: Apr 27, 2007
Posts: 18
You might want to look at classes TreeSet and interface Comparable. Check the Java Documentation for more information. A TreeSet is an abstract data type representing a set that maintains an order on its elements. These elements must be Comparable. Also, method sort from Collections might be worth looking at.

If you want to implement the actual sorting, you might want to look at
- Insertion sort (small number of elements)
- Merge sort (good worst case time for large number of elements)
- Quicksort (good expected time for large number of elements)
- Counting sort (if you know the maximum capacity and are willing to waste some space,
this will be the fastest)

(Wikipedia them for pseudocodes).

[ April 03, 2008: Message edited by: Alberto Caraz ]
[ April 03, 2008: Message edited by: Alberto Caraz ]
Pepo moussa
Ranch Hand

Joined: Mar 20, 2008
Posts: 36
well its kind a different for a treeSet, the algorithm. i already have a insert method in my class so what i need now the algorithm for how sorting by capacity should be done or look like ,
Mintoo kumar
Ranch Hand

Joined: Aug 21, 2007
Posts: 61
Can you please elaborate on your Questation like ,what objects your list will conatins?
Pepo moussa
Ranch Hand

Joined: Mar 20, 2008
Posts: 36
my list will contain rooms , room object should look like that example ("AZY","B212",300) ->("building name","room number",capacity) the sorting should be done by capacity .note i have a getData and next methods in the node class.
[ April 04, 2008: Message edited by: I moussa ]
Alberto Caraz
Greenhorn

Joined: Apr 27, 2007
Posts: 18
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#sort(java.util.List,%20java.util.Comparator)
Pepo moussa
Ranch Hand

Joined: Mar 20, 2008
Posts: 36
thanks for directing me to sun website,it was not helpful but thanks anyway
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Then you should try for your own sorting algorithm , which sort on 'capacity' and As Alberto Caraz said ,
If you want to implement the actual sorting, you might want to look at
- Insertion sort (small number of elements)
- Merge sort (good worst case time for large number of elements)
- Quicksort (good expected time for large number of elements)
- Counting sort (if you know the maximum capacity and are willing to waste some space,
this will be the fastest)

(Wikipedia them for pseudocodes).


You got those algorithm by googling , try to implement it in java, and then if you face problem (a specific to java) , we are here to solve !!


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Pepo moussa
Ranch Hand

Joined: Mar 20, 2008
Posts: 36
eventually i had to change my codes.and i did a insert by order method but i got one problem in this method till now that it only inserts the 1st lowest value and that it, here is my code if anyone can find a problem on it please let me know thanks



[ April 05, 2008: Message edited by: I moussa ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: linked list problem
 
Similar Threads
Circular Linked List
LinkedList Problem
maximu capacity of all collections..?
problem in String buffer rezises
Implementing Comparable, crafting compareTo with Set class