Here you can find the source of selectionSort(int[] arr)
public static void selectionSort(int[] arr)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; public class Main { public static void selectionSort(int[] arr) { System.out.println(Arrays.toString(arr)); int counter = 0; boolean swapRequired = false; for (int i = 0; i < arr.length - 1; i++) { int minArrIndex = i; swapRequired = false;//from w w w .ja va2 s . c o m for (int j = i + 1; j < arr.length; j++) { if (arr[j] < arr[minArrIndex]) { minArrIndex = j; swapRequired = true; } counter++; } if (swapRequired) { int temp = arr[i]; arr[i] = arr[minArrIndex]; arr[minArrIndex] = temp; System.out.println(Arrays.toString(arr)); } } System.out.println(Arrays.toString(arr)); System.out.println("#" + counter); } }