This week's book giveaway is in the JavaScript forum. We're giving away four copies of Getting MEAN with Mongo, Express, Angular, and Node and have Simon Holmes on-line! See this thread for details.

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 ]

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

posted

0

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 ,

Can you please elaborate on your Questation like ,what objects your list will conatins?

Pepo moussa
Ranch Hand

Joined: Mar 20, 2008
Posts: 36

posted

0

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 ]

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

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