How to use Java language to implement selective sorting algorithm
Editor to share with you how to use the Java language to achieve the selection sorting algorithm, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article. Let's learn about it!
Select sort
The idea of choosing sorting is as follows: first, find the smallest element in the array, pick it out, and swap it with the first element of the array. Second, continue to find the smallest element among the remaining elements, pick it out, and swap positions with the second element of the array, so loop until the sorting of the entire array is complete.
As for the choice of big or small, it doesn't matter, you can also choose the largest row each time, or you can choose the smallest row every time, as long as your sorting method is in this way, it is called selective sorting.
(ordered area, disordered area). Find the smallest element in the disordered area to follow the ordered area. Logarithmic array: more comparison, less change.
Java implementation selection sorting package com.zy.test;import java.util.Arrays;public class SelectSort {public static void main (String [] args) {System.out.println ("SelectSort"); int [] arr= {6 arr= 3, 8, 2, 2, 9, 1}; System.out.println (Arrays.toString (arr)); for (int item0, Tinci)