随笔分类 - 經典排序
常見
6.堆排序(不稳定)
摘要:package com.wang.principle; public class Test2 { public static void main(String[] args) { int[] arr = {49, 38, 65, 97, 76, 13, 27, 50}; //int[] c = {
阅读全文
5.快排(不稳定)
摘要:public static int Partition(int[] nums,int left,int right){ int prvot=nums[left]; while (left<right) { while (left<right&&nums[right]>=nums[left])righ
阅读全文
4.归并排序(稳定)
摘要:public static void main(String[] args) { int[] arr = {49, 38, 65, 97, 76, 13, 27, 50}; //int[] c = { 13, 38, 65, 97, 76, 13, 2, 50 };//稳定性判断 rec(arr,0
阅读全文
3.插入排序
摘要:/** * 插入排序 */ public static void insertSort(int[] arr) { int length = arr.length; for (int i = 1; i < length; i++) {//从第2个数字开始 for (int j = i - 1; j >
阅读全文
2.冒泡排序(稳定)
摘要:/** * 冒泡排序 */ public static void bubbleSort(int[] arr) { int length = arr.length; for (int i = 1; i < length; i++) {//比较趟数为数据量-1 for (int j = 0; j < l
阅读全文
1.选择排序(不稳定)
摘要:package com.wang.principle; public class Tets1 { /** * 选择排序 */ public static void selectionSort(int[] a) { int length=a.length; for(int i=0;i<length;i
阅读全文