加藤惠人气高是假的:求几种排序法的算法

来源:百度文库 编辑:高考问答 时间:2024/05/05 09:07:38
什么插入排序,起泡法,希尔排序,快速排序的

看看数据结构!
http://student.zjzk.cn/course_ware/data_structure/web/paixu/paixu8.1.1.1.htm

提供JAVA版的两种

public void bubbleSort(int a[]) { //数组的冒泡排序
int n = a.length;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1; j++) {
if (a[j] > a[j + 1]) {
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
}

public void selectSort(int a[]) { //数组的选择排序
for (int n = a.length; n > 1; n--) {
int i = max(a, n);
int temp = a[i];
a[i] = a[n - 1];
a[n - 1] = temp;
}
}