插入排序
1.伪代码及算法描述:
2.C/C++代码实现:
#include<iostream.h>
void InsertionSort(int arr[],int n)
{
int key;
int i;
for(int j=1;j<n;j++)
{
key=arr[j];
i=j-1;
while(i>=0&&key<arr[i])
{
arr[i+1]=arr[i];
i--;
}
arr[i+1]=key;
}
}
void DisPlay(int arr[],int n)
{
for(int i=0;i<n;i++)
cout<<arr[i]<<"";
cout<<endl;
}
void main()
{
int a[]={10,9,8,7,6,5,4,3,2,1};
DisPlay(a,10);
InsertionSort(a,10);
DisPlay(a,10);
}