插入排序

萝らか妹 提交于 2019-12-02 00:16:32

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;
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!