[Java SE] How to Use Java to achieve direct selection and sorting, and sejava to achieve sorting

Source: Internet
Author: User
Tags java se

[Java SE] How to Use Java to achieve direct selection and sorting, and sejava to achieve sorting

Abstract: Direct selection of sorting is a kind of sorting, but its sorting algorithm is faster than Bubble sorting, because its algorithm is relatively simple, therefore, it is also suitable for beginners to learn and master.

1 package liuenci.cn. package_3; 2 3 public class SelectSort {4 5/** 6 * directly select sort 7 */8 public static void main (String [] args) {9 // TODO Auto-generated method stub10 // create an unordered array 11 int [] array = }; 12 // create a directly ordered object 13 SelectSort sorter = new SelectSort (); 14 // call the directly selected algorithm to sort the array by 15 sorter. sort (array); 16} 17 public void sort (int [] array) {18 int index; 19 for (int I = 1; I <array. length; I ++) {20 index = 0; 21 for (int j = 1; j <= array. length-I; j ++) {22 if (array [j]> array [index]) {23 index = j; 24} 25 // swap in location array. two numbers 26 int temp = array [array. length-I]; 27 array [array. length-I] = array [index]; 28 array [index] = temp; 29} 30 31} 32 showArray (array ); 33} 34 public void showArray (int [] array) {35 // TODO Auto-generated method stub36 for (int I = 0; I <array. length; I ++) {37 int num = array [I]; 38 System. out. print (num + ""); 39} 40 System. out. println (); 41} 42 43}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.