Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Java language to implement selective sorting algorithm

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report