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 implement Array selection sorting in java

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Java how to achieve array selection sort, for this problem, this article details the corresponding analysis and solution, hoping to help more small partners who want to solve this problem find a simpler and easier way.

public static void main(String[] args) { //sort array int[] arr = {5,6,3,1,8,7,2,4}; //minimum numerical subscript int minIndex = 0; //array length int arrLen = arr.length; //array length minus 1 is because the last one after the previous number sorting is the maximum or minimum value for (int i = 0; i

< arrLen - 1; i++) { minIndex = i; for (int j = i + 1; j < arrLen; j++) { //比较运算符>

Sort from small to large, if you need to sort from large to small, change to

< if (arr[minIndex] >

arr[j]) { minIndex = j; } } //replace the minimum value to the front int temp = arr[i]; arr[i] = arr[minIndex]; arr[minIndex] = temp; //after sorting System.out.print("Result after sorting round"+(i+1)+":"); for (int item : arr) { System.out.print(item); } System.out.println(""); } //after sorting System.out.print("Sort result: "); for (int item : arr) { System.out.print(item); }} Execution Results:

1st round sorting results: 16358724

Results after the second round sorting: 12358764

3rd round sorting results: 12358764

4th round sorting results: 12348765

The fifth round of sorting results: 12345768

6th round sorting result: 12345678

7th round sorting result: 12345678

Sorted results: 12345678

About java how to achieve the array selection sorting problem solution to share here, I hope the above content can have some help for everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.

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

Internet Technology

Wechat

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

12
Report