Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Java language to implement selective sorting algorithm

Shulou Source: shulou.com Published: 2022-06-01 11:47:49 09月28日 Update

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)

Tags: Sort element select minimum array position sequence article algorithm language order content idea maximum and so on it doesn't matter it doesn't matter most of the means Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux OPPO Reno Shulou Technology Apple Shulou Tech Info