View Single Post
  #1 (permalink)  
Old 04-05-2008, 12:09 PM
Java Tip Java Tip is offline
Moderator
 
Join Date: Nov 2007
Posts: 1,657
Java Tip will become famous soon enoughJava Tip will become famous soon enough
How to sort a list using Bubble sort algorithm
This code is the implementation of the bubble sort algorithm.

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); } }
Reply With Quote
Sponsored Links