VC++ C++ C# Algorithm

C++博客 首页 新随笔 联系 聚合 管理
  21 Posts :: 3 Stories :: 31 Comments :: 0 Trackbacks
 1 int  A[ 10 ] = { 1 , 2 , 5 , 7 , 3 , 14 , 78 , 25 , 11 , 14 } ;
 2 void  InsertSort( int  a[], int  size)
 3 {
 4      for ( int  i = 1 ; i < size; i ++ )
 5      {
 6          int  key = a[i];
 7          int  j = i - 1 ;
 8          while (a[j] > key  &&  j >= 0 )
 9          {
10             a[j + 1 ] = a[j];
11             j -- ;
12         }

13         a[j + 1 ] = key;
14     }

15 }

16
17 int  _tmain( int  argc, _TCHAR *  argv[])
18 {
19
20     InsertSort(A, sizeof (A) / sizeof (A[ 0 ]));
21      for ( int  i = 0 ; i < 10 ; i ++ )
22      {
23         printf( " %d\n " ,A[i]);
24     }

25     ::system( " pause " );
26      return   0 ;
27 }

28
posted on 2007-03-15 16:32 大熊猫 阅读(276) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理