码迷,mamicode.com
首页 > 编程语言 > 详细

插入排序

时间:2019-10-22 22:04:42      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:cts   prot   owa   size   main   sel   namespace   array   count   

include

using namespace std;
//Function prototype
int* selectSort(int ,int);
void showArray(const int [],int);
int main()
{
int array[] = {7,2,11,5,9,10};
int size = sizeof(array)/sizeof(array[0]);
showArray(array,size);
selectSort(array,size);
showArray(array, size);
cout <<array<< endl;
return 0;
}
int
selectSort(int p,int size)
{
for (int i=1;i<size;i++)
{
int t =
(p + i);
int j;
for (j = i-1;j>=0&&t<(p+j);j--)
{
(p + j+1) = (p+j);
}
(p + j + 1) = t;
}
return p;
}
void showArray(const int array[], int size)
{
for (int count=0;count<size;count++)
{
cout << array[count] <<" ";
}
cout << endl;
}

插入排序

标签:cts   prot   owa   size   main   sel   namespace   array   count   

原文地址:https://www.cnblogs.com/131415-520/p/11722696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!