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

An example Analysis of Java selection sorting

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

Share

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

This article mainly introduces "Java selection sorting example Analysis". In daily operation, I believe many people have doubts about Java selection sorting example analysis problems. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "Java selection sorting example Analysis". Next, please follow the editor to study!

Selective sorting principle

① assumes that the element at the first index is the minimum, and compares it with other values. If the element at the current index is greater than the value at some other index, it assumes that the value at the other index is the minimum, and finally finds the index where the minimum is located.

② swaps the value at the first index and the index where the minimum value is located

Select sort API design class name Selection constructor Selection (): create Selection object member method

1.public static void sort (Comparable [] a): sorts the elements in an array

2.private static boolean greater (Comparable v comparison w): judge whether v is greater than w

3.private static void exchange (Comparable [] a drawing int iline int j): swap the values at index I and index j in the an array

Select the sorting code to sort the elements in public class Selection {/ / an array a to sort public static void sort (Comparable [] a) {for (int item0

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