# sorting a given array by applying the Bubble Sort algorithm

Page 1 of 1

## 2 Replies - 241 Views - Last Post: 28 March 2012 - 05:44 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=272826&amp;s=8c364d5e5a3c3e602d39e8d036c712f3&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Dol

Reputation: 0
• Posts: 1
• Joined: 28-March 12

# sorting a given array by applying the Bubble Sort algorithm

Posted 28 March 2012 - 01:18 AM

How do i write a method which sorts a given array by applying the Bubble Sort algorithm, i.e. linearly comparing neighbouring elements and swap them as necessary until the array is sorted. But the given array does not contain elements of type int but contain arbitrary objects (i.e. any object of classes implementing the Comparable interface).
Is This A Good Question/Topic? 0

## Replies To: sorting a given array by applying the Bubble Sort algorithm

### #2 ILoveJava

• D.I.C Regular

Reputation: 28
• Posts: 369
• Joined: 12-March 12

## Re: sorting a given array by applying the Bubble Sort algorithm

Posted 28 March 2012 - 03:00 AM

We don't write methods for you. Try searching around on Google for a method on how to do it (I'm sure there is at least one of them out there), then modify it for how you want it, then, if all else fails after that, post back here.

### #3 pbl

• There is nothing you can't do with a JTable

Reputation: 8032
• Posts: 31,202
• Joined: 06-March 08

## Re: sorting a given array by applying the Bubble Sort algorithm

Posted 28 March 2012 - 05:44 PM

Our Tutorial section and the Code Snippets section are full of examples of sorts of all sorts