
排序算法
基本排序方法
北半球的年少时光
这个作者很懒,什么都没留下…
展开
-
选择排序
public class SelectSort { public static int[] srot(int[] targe) { for (int i = 0; i < targe.length; i++) { int min = i; for (int j = i; j < targe.length; j++) { if (targe[j] < targe[min]) { ...原创 2020-05-09 07:54:59 · 143 阅读 · 0 评论 -
插入排序
public class InsertSort { public static int[] insert(int[] targe) { for (int i = 0; i < targe.length; i++) { int temp = targe[i]; while (i > 0 && targe[i - 1] > temp) { targe[i] = targ...原创 2020-05-09 07:54:20 · 162 阅读 · 0 评论 -
归并排序
import java.util.Arrays; public class MergeSort { public static void main(String[] args) { int[] arr = { 9, 8, 7, 6, 5, 4, 3, 2, 1 }; sort(arr); System.out.println(Array...原创 2020-03-31 08:21:41 · 108 阅读 · 0 评论 -
1.快速排序
public class QuickSort { public static int[] sort(int[] targe, int low, int high) { if (low >= high) return targe; // 递归出口 int l = low;// 本次排序的起始点位置 int h = ...原创 2020-03-28 12:08:35 · 96 阅读 · 0 评论 -
2.冒泡排序
public class BubbleSrot { public static int[] sort(int[] targe) { boolean flag = true; for (int i = targe.length - 1; i > 0 && flag; i--) {// 外层循环表示本次内层循环要确定的最大或最小数的位置 ...原创 2020-03-28 12:09:41 · 191 阅读 · 0 评论