Asp.net 学习资料

伦惠峰

直接插入排序

#include<iostream.h>
void InsertSort(int A[],int n)
{
 int x;
 int i,j;
 for(i=1;i<n;i++)
 {
  x=A[i];
  for(j=i-1;j>=0;j--)
   if(x<A[j])
    A[j+1]=A[j];
   else
    break;
   A[j+1]=x;
 }
}

void main()
{
 int a[]={12,32,14,25,98,24,44};
 InsertSort(a,7);
 for(int i=0;i<7;i++)
 cout<<a[i]<<" ";
 cout<<endl;
}

posted on 2007-08-13 21:41  伦惠峰  阅读(125)  评论(0)    收藏  举报

导航