File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes bubble sorting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "bubble sorting" Watch "bubble sorting" New topic

bubble sorting

Jamie Cotton

Joined: Nov 12, 2004
Posts: 16
Hiya i have an array of objects called messageArray which is created by converting an ArrayList to an Array

The array has objects in it each called message and a message is made up of
Now i want to sort the new Array which i have created by the sender by using bubble sort but not sure how can any help ?

At the moe the print out is

but after the sort i want

[ November 20, 2004: Message edited by: Jamie Cotton ]
[ November 20, 2004: Message edited by: Jamie Cotton ]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
why do it like that?
And why care about the algorithm at all?

The easiest way would be to make your class Comparable and pipe the List into a SortedSet. It will then be sorted automagically.

john guthrie
Ranch Hand

Joined: Aug 05, 2002
Posts: 124
the JDSL has some specific sorts (e.g. quicksort, mergesort), but not bubble sort. see if any of those give you good enough performance
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Is there any reason you want to use bubble sort? I can understand if this is a homework assignment and the teacher has specified that you do so. However, if not, you should use Collections.sort() on the original ArrayList instead. In fact, why are you converting the ArrayList into an array? Also, if you want the list sorted, there are other collections that are better to use. TreeSet will put the items in a sorted order as you add them. You can also use an Iterator to iterate over the set (or even the original ArrayList), rather than converting it into an array.



Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: bubble sorting
It's not a secret anymore!