MCPcopy Create free account
hub / github.com/Manvityagi/PW-Skills-Java-Course-Codes / Main

Class Main

Lecture 38 - Selection Sort/src/Main.java:1–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1public class Main {
2 static void selectionSort(int[] arr){
3 int n = arr.length;
4 for(int i = 0; i < n-1; i++){ // i represent the current index
5 //Find the minimum element in unsorted part of array
6 int min_index = i;
7 for(int j = i+1; j < n; j++){
8 if(arr[j] < arr[min_index]){
9 min_index = j;
10 }
11 }
12 //swap current element and minimum element -> current index i will have correct element
13 // a[min_index], a[i]
14 int temp = arr[i];
15 arr[i] = arr[min_index];
16 arr[min_index] = temp;
17 }
18 }
19 public static void main(String[] args) {
20 int[] arr = {7, 4, 1, 2, 100, 90};
21 selectionSort(arr);
22 for(int i = 0; i < arr.length; i++){
23 System.out.print(arr[i] + " ");
24 }
25 }
26}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected