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

Introduction and implementation of selective sorting in Java algorithm

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "the introduction and implementation of selection sorting in Java algorithm". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "the introduction and implementation of selection sorting in Java algorithm"!

Select sort (Selection Sort)

Brief introduction:

Selective sorting (Selection-sort) is a simple and intuitive sorting algorithm. How it works: first find the smallest (large) element in the unsorted sequence, store it at the beginning of the sorted sequence, then continue to find the smallest (largest) element from the remaining unsorted elements, and then put it at the end of the sorted sequence. And so on until all the elements are sorted.

Algorithm description:

First find the smallest (large) element in the unsorted sequence and store it at the beginning of the sorted sequence, then continue to find the smallest (large) element from the remaining unsorted elements, and then put it at the end of the sorted sequence. And so on until all the elements are sorted.

To put it simply, record a position, and then find the minimum (maximum) and put it in this position.

Java code

Public class SelectionSort {public static void main (String [] args) {int [] array = new int [] {0Arrays.toString [] array) {for (int I = 0; I) {for (int I = 0; I)

< array.length;i++){ //标记该位置的值,暂且默认为最小值 int temp = array[i]; //循环,找到最小值 for(int j = i + 1; j < array.length;j++){ if(temp >

Array [j]) {temp = array [j]; array [j] = array [I]; array [I] = temp;}} array [I] = temp;} return array;}} so far, I believe you have a deeper understanding of "the introduction and implementation of selective sorting in Java algorithm". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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