Get the App
SLTechnology News&Howtos  ›  Development  › 

An example Analysis of Java selection sorting

Shulou Source: shulou.com Published: 2022-06-02 13:52:52 09月15日 Update

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

Tags: Sort select index analyze minimum element data learning complexity complexity array method time loop location more number of times help practical next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux macOS NVidia Docker Shulou Tech Info