Results 1 to 4 of 4
-
How to sort a list using Bubble sort algorithm
This code is the implementation of the bubble sort algorithm.
Java Code:public class BubbleSortExp { public static void main(String[] args) { int s[] = { 23, 12, 466, 22, 1 }; int temp; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4 - i; j++) { if (s[j + 1] < s[j]) { temp = s[j + 1]; s[j + 1] = s[j]; s[j] = temp; } } } System.out.println("Sorted Array"); for (int i = 0; i < s.length; i++) { System.out.println(s[i]); } System.out.println(s); } }
- 04-11-2008, 06:51 AM #2
Ewww... :)
The dreaded and most fundamental, good for a small number of elements, but horrible for larger than.. say.. 10 elements? :D
What else you got for us Chief ? ;)Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 04-11-2008, 07:34 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What you mean Captain, its work fine for 15 numbers also. :)
I'm worried why did you say that for 10 elements it is horrible. ;)
- 04-29-2008, 08:04 PM #4
Similar Threads
-
Bubble Sort in Java
By Java Tip in forum AlgorithmsReplies: 0Last Post: 04-15-2008, 07:42 PM -
need help with bubble sort
By lowpro in forum New To JavaReplies: 3Last Post: 12-17-2007, 05:27 PM -
how to sort
By Feng in forum New To JavaReplies: 1Last Post: 11-20-2007, 06:56 AM -
Help with sort algorithm
By zoe in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:09 AM -
Insertion sort algorithm
By Albert in forum Advanced JavaReplies: 2Last Post: 06-28-2007, 08:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks