排序算法
潜心修炼的蜗牛
修炼 修炼!!!
展开
-
简单的快速排序
#include<stdio.h>int parition(int*ar,left,right){int i=left;int j=right;int tmp=ar[i];while(i<j){while(i<j && tmp<=ar[j]) //这里加上等于号可防止待排序列中有相同数值时出现死循环{j-- ;}if(i&l...原创 2019-04-02 17:46:49 · 95 阅读 · 0 评论 -
简单的选择排序
void slectsort(int n, int* ar){int i = 0;for (; i < n-1; i++){int k = i;for (int j = i + 1; j < n; j++){if (ar[j]<ar[k]){k = j;}}swap(ar[i] , ar[k]);}}int main(){int ar[20] ...原创 2019-04-02 18:16:43 · 90 阅读 · 0 评论 -
简单的插入排序
void insertsort(int n, int * ar){for (int i = 1; i < n; i++){int tmp = ar[i];int j = i - 1; if (ar[j]>ar[j + 1]) { **do { ar[j + 1] = ar[j]; j--; } while (j>=0 &&tm...原创 2019-04-04 15:49:14 · 114 阅读 · 0 评论 -
简单的冒泡排序
void bubblesort(int n, int *ar){int i = 1;for (; i < n; i++){int tag = 1;for (int j = 0; j < n-i; j++){if (ar[j]>ar[j + 1]){swap(ar[j], ar[j + 1]);tag = 0;}} if (tag ) { brea...原创 2019-04-04 16:06:35 · 89 阅读 · 0 评论