插入排序算法!

来源:互联网 发布:mac安装win8教程 编辑:程序博客网 时间:2024/06/15 02:26
#include <iostream>using namespace std;void InsertionSort(int *pArr, int nLen){   int  j=0;                                              //     插入的位置代号,作为函数的全局变量。     //不能重复定义。for (int i=1;i<nLen;i++){if (pArr[i]<pArr[i-1]){int temp=pArr[i];      ;                     //从第二元素开始,如果比前一个元素小,就取出来  //把j放在这  是为了使J的值保留。for(j=i-1;j>=0 && pArr[j]>temp;j--){pArr[j+1]=pArr[j];}pArr[j+1]=temp;}}}
说明:nLen为整型数组的长度!!!!!!!!!!!!!!!!


0 0