In Java, when using array to sort the function, there are four kinds of methods: fast sorting method, bubbling method, choosing Sort method, inserting sort method.
The fast sorting method mainly uses a method arrays.sort () implementation in arrays.
The bubbling method uses a traversal array to compare the minimum or maximum values by a continuous comparison.
The selection sort method is to use the first data of the array as the maximum or minimum value, and then to output an ordered array by comparing loops.
package com.study.test;import java.util.arrays;public class testarrsort { public static void main (String[] args) { sortarr () ; } public static Void sortarr () { int arr[] = { 3, 5, 2, 11}; arrays.sort (arr); system.out.println (arrays.tostring (arr)); } // sort the array, the Bubbling method // bubble method is used to compare the traversal arrays, and the minimum or maximum value is traversed by a constant comparison. &NBSP;&NBSP;&NBSP;&NBSP;PUBLIC&NBSP;STATIC&NBSP;VOID&NBSP;SORTARR1 () { int arr[] = { 3, 5, 2, 11, 35, 20, 15 }; for (int i = 0; i < arr.length; i++) { for (int j = i + 1; j < arr.length; j++) { if (Arr[j] < arr[i]) { int tmp = 0; tmp = arr[j]; arr[j] = arr[i]; arr[i] = tmp; } } system.out.println (Arr[i]); } } // sorting by array, sorting method // The selection sort method is to use the first data of the array as the maximum or minimum value, and then to output an ordered array by comparing loops. &NBSP;&NBSP;&NBSP;&NBSP;PUBLIC&NBSP;STATIC&NBSP;VOID&NBSP;SORTARR2 () { int arr[] = { 3, 5, 2, 11, 35, 20, 15,200,99 }; for (int i = 0; i < arr.length ; i++) { int min = i; for (int j = i + 1; j < arr.length; j++) { if (arr[min] > &NBSP;ARR[J]) { min = j; } } if (min != i) { int temp = arr[i]; arr[i] = arr[min]; arr[min] = temp; } system.out.println (Arr[i]); } }}
This article is from the "Sima" blog, make sure to keep this source http://9274590.blog.51cto.com/9264590/1761086
Three ways to sort Ava array elements