排序
FreedanyTsui
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
快速排序代码
#include<stdio.h> #include<stdlib.h> #define MAX 10 typedef struct sort { int length; int a[MAX+1]; }Sort; void init(Sort *L) { L->length=MAX; printf("请输入10个待排序的数\n"); for(int i=0;i<L->length;i++) { scanf("%3d",&L->a[i].原创 2021-11-16 19:49:14 · 724 阅读 · 0 评论 -
插入排序——直接插入排序
#include <stdio.h> #include <stdlib.h> /* 直接插入排序可以满足链式存储结构 每一轮的排序是可以造成局部有序 最好的时间复杂度为O(n)(前提条件:在基本有序的情况下) 最坏的时间复杂度为O(n²) 平均时间复杂度为O(n²) 是一个稳定的排序算法 */ 插入排序(耿国华) 下标0的位置作为哨兵 然后每一个遍历的元素与下标为零的元素做一次比较 void InsertSort(int r[],int length) { int ...原创 2021-11-04 09:53:07 · 699 阅读 · 0 评论 -
插入排序——折半插入排序
#include<stdlib.h> #include<stdio.h> /* 折半插入排序是稳定的排序 查找的时间复杂度可以达到O(log n) 平均时间复杂度为O(n²) 特点:只适用于顺序存储的情况 */ 折半插入排序(耿国华) 书上完整版 void BinSort(int r[], int length) { int x, low, high, mid; for (int i = 2;i <= length;++i) { ...原创 2021-11-04 09:45:42 · 247 阅读 · 0 评论 -
交换排序——起泡排序、冒泡排序
#include<stdlib.h> #include<stdio.h> /* 起泡排序、冒泡排序 是稳定的排序 每一轮产生的子序列是全局有序,每一趟一定会保证一个最小元素排序成功 最好情况O(n) 前提条件是有序的 最坏情况O(n²) 平均时间O(n²) */ 冒泡排序 耿国华变动版 实现数组从下标0到length的全排序 void BubbleSort(int r[],int n){ bool change = true; int x; for (i...原创 2021-11-04 09:44:12 · 745 阅读 · 0 评论 -
选择排序——简单选择排序
#include<stdlib.h> #include<stdio.h> /* 选择最小的数来作为基准进行排序 简单选择排序是不稳定排序 不论数组是否有序,时间复杂度都为O(n²) */ //简单选择排序排序 耿国华版本 可运行但是不能实现从下标0的全排 void SelectSort(int r[], int n) { int k, i; for (i = 1;i <= n - 1;++i) { k = i; f...原创 2021-11-04 09:53:33 · 197 阅读 · 0 评论
分享