Selection Sort Using Java

 package demo;


import java.util.Arrays;

import java.util.stream.Collectors;


public class SelectionSort {

public static void main(String[] args) {

int arr[] = { 2, 4, 1, 5, 3, 6, 9, 8, 7 };


for (int i = 0; i < arr.length; i++) {

int minId = i;

for (int j = i + 1; j < arr.length; j++) {

if (arr[j] < arr[minId]) {

minId = j;

}

}


int temp = arr[minId];

arr[minId] = arr[i];

arr[i] = temp;


}


System.out.println(Arrays.stream(arr).boxed().collect(Collectors.toList()));

}


}


Comments

Popular posts from this blog

3 Lines of Code And You Can Download Your Favourite Youtube Video.

Leetcode Problem(Easy) Roman to Integer

Leetcode : (Find Minimum in Rotated Sorted Array)