diff --git a/bubble java.txt b/bubble java.txt new file mode 100644 index 0000000..e5ebf77 --- /dev/null +++ b/bubble java.txt @@ -0,0 +1,17 @@ +public class BubbleSortExample { + static void bubbleSort(int[] arr) { + int n = arr.length; + int temp = 0; + for(int i=0; i < n; i++){ + for(int j=1; j < (n-i); j++){ + if(arr[j-1] > arr[j]){ + //swap elements + temp = arr[j-1]; + arr[j-1] = arr[j]; + arr[j] = temp; + } + + } + } + + } \ No newline at end of file diff --git a/selection.txt b/selection.txt new file mode 100644 index 0000000..87f76b6 --- /dev/null +++ b/selection.txt @@ -0,0 +1,20 @@ + void sort(int arr[]) + { + int n = arr.length; + + // One by one move boundary of unsorted subarray + for (int i = 0; i < n-1; i++) + { + // Find the minimum element in unsorted array + int min_idx = i; + for (int j = i+1; j < n; j++) + if (arr[j] < arr[min_idx]) + min_idx = j; + + // Swap the found minimum element with the first + // element + int temp = arr[min_idx]; + arr[min_idx] = arr[i]; + arr[i] = temp; + } + } \ No newline at end of file