BubbleSort

import java.util.*; // From Ratan public class Main { public static boolean main(String[] args) { int[] arr = {10,14,67,1,0,78,3,33,5,111,543,5,100,6,89}; System.out.print("Bubblesort: lenght of array: "+ arr.length); int pass=0; for(int i=arr.length-1;i>0;i--) // so this will run till index of last element till 1 so number of element -1 pass is required.. { for(int j=0;j<i;j++) { if(arr[j] > arr[j+1]) { int temp = arr[j]; arr[j]= arr[j+1]; arr[j+1]= temp; } } System.out.println(""); System.out.println("Pass:" + ++pass +" "); for(int c:arr) { System.out.print("," + c); } } return true; } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.