摘要: 常用的内部排序方法有:交换排序(冒泡排序、快速排序)、选择排序(简单选择排序、堆排序)、插入排序(直接插入排序、希尔排序)、归并排序、基数排序(一关键字、多关键字)。 一、冒泡排序: 1.基本思想: 两两比较待排序数据元素的大小,发现两个数据元素的次序相反时即进行交换,直到没有反序的数据元素为止。 阅读全文
posted @ 2019-03-20 12:41 赵钱富贵 阅读(913) 评论(0) 推荐(0) 编辑
摘要: void swap(int *a,int *b){ int temp=*a; *a=*b; *b=temp; } void selectSort(int *a,int n){ for(int i=0;i<n-1;i++){ int min=i; for(int j=i+1;j<n;j++){ if( 阅读全文
posted @ 2019-03-20 12:15 赵钱富贵 阅读(101) 评论(0) 推荐(0) 编辑
摘要: void insertionSort(int *a,int n){ for(int i=1;i=0&&a[j]>key){ a[j+1]=a[j]; j--; } a[j+1]=key; } } 阅读全文
posted @ 2019-03-20 08:20 赵钱富贵 阅读(64) 评论(0) 推荐(0) 编辑