摘要: 题意:给出一个数组,如 [1,4,6,5,9,10] , 如果将6,5进行从小至大排序,那么就能够得到一个有序序列,而且这个是最小的需排序单元,长度为2。 这个问题如果用一般的方法想,很复杂。 注意接下来介绍的性质:如果一个数组是有序的(假设从小至大),那么,遍历每个元素arr[i]<=arr[i+ 阅读全文
posted @ 2020-02-23 18:36 B_luePhantom 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 1 // 插入排序的写法:即使不需要哨兵,也可以写的很流畅。 2 int* insertionSort(int* A, int n) { 3 // write code here 4 for(int i=1;i<n;i++){ 5 int j=i-1,tmp=A[i]; 6 while(j>=0 & 阅读全文
posted @ 2020-02-23 17:23 B_luePhantom 阅读(221) 评论(0) 推荐(0) 编辑