6-7-2.cpp

来自「学习c++的ppt」· C++ 代码 · 共 21 行

CPP
21
字号
#include <iostream.h>
void InsertSort(int  slist[], int  n)
{      int  temp;
       int i,j;
       for (i=1; i < n; i++)  {
             temp = slist[i];
	   j=i;
	   while (j>0 && temp < slist[j-1])  {
	         slist[j]=slist[j-1];
	         j--; 
             }    //查找与移动同时做
	   slist[j] = temp;	
       }
}
void  main()
{   int  a[] =  {8, 6, 7, 9, 4, 5, 2};
     InsertSort(a,  7);  cout << "排序后的数据是:";
     for(int i=0; i < 7; i ++)  cout << a[i] << ",";
     cout << endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?