• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

linked list problem

 
Pepo moussa
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please elaborate on your Questation like ,what objects your list will conatins?
 
Pepo moussa
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Pepo moussa
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for directing me to sun website,it was not helpful but thanks anyway
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!
 
Pepo moussa
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic