临沂怎么做网站,长春有哪些互联网大厂,网络运营商官网,discuz绿色带门户手机网站模板选择排序
遍历整个待排序的数组#xff0c;从第一个元素开始。在未排序的部分中#xff0c;找到最小#xff08;或最大#xff09;的元素#xff0c;并将其与第一个元素交换位置。接着从第二个元素开始#xff0c;重复步骤2#xff0c;直到所有元素都被排序
迭代版 递…选择排序
遍历整个待排序的数组从第一个元素开始。在未排序的部分中找到最小或最大的元素并将其与第一个元素交换位置。接着从第二个元素开始重复步骤2直到所有元素都被排序
迭代版 递归版 Time Complexity C(n): the number of element comparisons 元素比较次数 Clearly, as n1, C(1)0; Procedure sort is invoked i1, and there are n elements in the array. Therefore ,in this call, there are n-1 element comparisons Therefore ,in this call, there are n-1 element comparisons plus the number of element comparisons that result from the recursive call sort(i1) to sort the array A[2..n]. We have:
插入排序
插入排序
1.从第一个元素开始该元素可以认为已经被排序 2.取下一个元素tem从已排序的元素序列从后往前扫描 3.如果该元素大于tem则将该元素移到下一位 4.重复步骤3直到找到已排序元素中小于等于tem的元素 5.tem插入到该元素的后面如果已排序所有元素都大于tem则将tem插入到下标为0的位置 6.重复步骤2~5