Here you find the source code for Bubble Sort Algorithm. This is a very basic level algorithm using to sort unsorted Number array. Most of the basic Software Engineering interviews, this is a common question raised.
Output
Try to do some modification on this code and add it as a comment.
//Copyrighted geekdecoders.blogspot.com public class bubbleSort{ public static void main(String args[]){ int array[] = {50,89,4,67,124,56,78,33,64,57,3}; System.out.println("\nIntegers Before Sort:\n"); for(int k=0; k < array.length; k++) System.out.print( array[k]+" "); System.out.println("\n"); //Sorting Starts int i,j,temp=0; for(i = 0; i < array.length; i++){ for(j = 1; j < (array.length-i); j++){ if(array[j-1] > array[j]){ temp = array[j-1]; array[j-1]=array[j]; array[j]=temp; } } } System.out.println("Sorted Array:\n"); for(int k = 0; k <array.length; k++) System.out.print(array[k]+" "); } }
Output
Try to do some modification on this code and add it as a comment.
Comments
Post a Comment