Posts

Showing posts with the label algorithms in java

Implement Bubble Sort in Java.

Image
*Bubble Sort:             Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. //Write a Java program for implementinng Bubble Sort. public class MyBubbleSort {          // logic to sort the elements      public static void bubble_srt( int array[]) {          int n = array.length;          int k;          for ( int m = n; m >= 0 ; m--) {              for ( int i = 0 ; i < n - 1 ; i++) {                  k = i + 1 ;                  if (array[i] > arr...