diff --git a/BubbleSort.class b/BubbleSort.class new file mode 100644 index 0000000..51b5984 Binary files /dev/null and b/BubbleSort.class differ diff --git a/BubbleSort.java b/BubbleSort.java new file mode 100644 index 0000000..42404b1 --- /dev/null +++ b/BubbleSort.java @@ -0,0 +1,35 @@ +class BubbleSort +{ + void bubbleSort(int arr[]) + { + int n = arr.length; + for (int i = 0; i < n-1; i++) + for (int j = 0; j < n-i-1; j++) + if (arr[j] > arr[j+1]) + { + // swap temp and arr[i] + int temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + } + } + + /* Prints the array */ + void printArray(int arr[]) + { + int n = arr.length; + for (int i=0; i= 0 && arr[j] > key) { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; + } + } + + // For print array + static void printArray(int arr[]) + { + int n = arr.length; + for (int i = 0; i < n; ++i) + System.out.print(arr[i] + " "); + + System.out.println(); + } + + // Driver method + public static void main(String args[]) + { + int arr[] = { 12, 11, 13, 5, 6 }; + + InsertionSort ob = new InsertionSort(); + ob.sort(arr); + + printArray(arr); + } +} \ No newline at end of file diff --git a/InsertionSort.class b/InsertionSort.class new file mode 100644 index 0000000..2fe7d7b Binary files /dev/null and b/InsertionSort.class differ