随笔分类 -  算法

常见排序,查找等
摘要:注:本文来自:https://www.cnblogs.com/developerY/p/3172379.html 算法过程: 1、初始化:构造一个10 n的二维数组,一个长度为n的数组用于存储每次位排序时每个桶子里有多少个元素。 2、循环操作:从低位开始(我们采用LSD的方式),将所有元素对应该位的 阅读全文
posted @ 2018-11-17 10:26 _sanjun 阅读(110) 评论(0) 推荐(0)
摘要:``` public class HeapSortDemo { public static void main(String[] args) { int[] arr = {9, 8, 7, 6, 5, 4, 3, 2, 1}; sort(arr); System.out.println(Arrays.toString(arr)); }... 阅读全文
posted @ 2018-11-17 10:11 _sanjun 阅读(144) 评论(0) 推荐(0)
摘要:``` public class MinHeapDemo { final static int MAX_LEN = 100; private int[] queue = new int[MAX_LEN]; private int size; public void add(int e) { if ( 阅读全文
posted @ 2018-11-17 10:11 _sanjun 阅读(93) 评论(0) 推荐(0)
摘要:``` public class BubbleSortDemo { public static void bubbleSort(int[] a) { //一次遍历,长度a.length 1,主要是第一个最终没影响 for (int i = 1; i a[j + 1]) { int temp = a[ 阅读全文
posted @ 2018-11-17 10:10 _sanjun 阅读(112) 评论(0) 推荐(1)
摘要:``` public class SelectionSortDemo { public static void selectSort(int[] a) { //从小到大,选择待排序的第一个数作为最小的值min int minIndex = 0; //最小值下标 int minTemp = 0; // 阅读全文
posted @ 2018-11-17 10:09 _sanjun 阅读(91) 评论(0) 推荐(0)
摘要:``` public class MergeSortDemo { public static void merge(int[] a, int low, int mid, int high) { //建立一个临时数组,大小为归并后大小 int[] temp = new int[high low + 1 阅读全文
posted @ 2018-11-17 10:08 _sanjun 阅读(90) 评论(0) 推荐(0)
摘要:``` public class QuickSortDemo { public static void quickSort(int[] arr) { sort(arr, 0, arr.length 1); } public static void sort(int[] arr, int low, i 阅读全文
posted @ 2018-11-17 10:07 _sanjun 阅读(91) 评论(0) 推荐(0)