
排序
ChasonPc
-
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
快速排序
#include <iostream>using namespace std;int partition(int arr[], int L, int R){ int pivot = arr[R]; int j = L; for(int i = L; i < R; i++){ if(arr[i] < pivot){ ...原创 2019-10-25 11:38:07 · 158 阅读 · 0 评论 -
计数排序
计数排序属于桶排的一种#include <iostream>using namespace std;void countSort(int a[], int n, int k){ int *c = new int[k+1]; int *b = new int[n]; int i, j; for(i = 0; i < k; i++){...原创 2019-10-20 16:48:21 · 100 阅读 · 0 评论 -
归并排序
#include <iostream>using namespace std;void merge(int a[], int first, int mid, int last){ int LEFT_SIZE = mid - first; int RIGHT_SIZE = last - mid + 1; int left[LEFT_SIZE]; i...原创 2019-10-19 18:01:08 · 227 阅读 · 0 评论 -
堆排序
#include <iostream>using namespace std;void swap(int tree[], int i, int j){ int temp = tree[i]; tree[i] = tree[j]; tree[j] = temp;}void HeapAdjust(int a[], int n, int i){ if(i >= n...原创 2019-10-12 17:53:38 · 110 阅读 · 0 评论 -
简单选择排序
#include <iostream>using namespace std;int swap(int &x, int &y){ int temp = x; x = y; y = temp;} void selectSort(int a[], int n){ int i, j, min; for(i = 0; i < n-1; ++i){...原创 2019-09-12 20:14:08 · 126 阅读 · 0 评论 -
直接插入排序
#include <iostream>using namespace std;void insertSort(int a[], int n){ int i,j,pivotKey; for(i = 1; i < n; i++){ if(a[i] < a[i-1]){ pivotKey = a[i]; ...原创 2019-09-17 22:38:25 · 111 阅读 · 0 评论 -
希尔排序
#include <iostream>using namespace std;void shellSort(int a[], int n){ int i, j, pivotKey, gap; for(gap = n/2; gap > 0; gap /= 2){ for(i = gap; i < n; i++){ pivotKey = a[i]; f...原创 2019-09-26 21:10:08 · 119 阅读 · 0 评论 -
冒泡排序及优化
#include <iostream>using namespace srd;void swap(int &x, int &y){ int temp; temp = x; x = y; y = temp;}void bubbleSort1(int a[], int n){ }int main(){}原创 2019-09-11 22:29:42 · 140 阅读 · 0 评论 -
常见的排序算法及时间复杂度
(1)简单的排序算法排序方法时间复杂度冒泡排序最好:O(n) 最坏:O(n2)简单选择排序O(n2)直接插入排序O(n2)改进的排序算法排序方法时间复杂度希尔排序O(n3/2)堆排序O(n*logn)归并排序O(n*logn)快速排序(快排)O(n*logn)...原创 2019-09-27 16:18:19 · 143 阅读 · 0 评论