C++排序,在线求解
小朋友们,“排序”是程序设计中最常见的需求,如果我们想在信息学中取得好成绩,排序是必须掌握的基础知识。本题没有更多要求,就是从小到大的排序~
Input
输入数据第一行是一个正整数C(C<=10),表示有C组测试用例。每组测试数据占一行,首先是一个正整数N(N<=1000),表示本组数据有N个整数,紧随其后的就是N个整数。Output
请输出从小到大排序后的结果。每组数据输出一行,每个数字后面是一个空格。Sample Input
23 2 1 39 1 4 7 2 5 8 3 6 9Sample Output
1 2 3 1 2 3 4 5 6 7 8 9最佳答案
楼上的随便网上抄了段程序贴上来了,完全不符题意
C++本身有排序,所以程序很简单,以下程序参考(注意按要求调整输入/输出格式)
其他回答
其它网友回答:
#include <iostream.h>
其它网友回答:
void SelectSort(int* pData,int Count)
其它网友回答:
{
其它网友回答:
int iTemp;
其它网友回答:
int iPos;
其它网友回答:
for(int i=0;i<Count-1;i++)
其它网友回答:
{
其它网友回答:
iTemp = pData[i];
其它网友回答:
iPos = i;
其它网友回答:
for(int j=i+1;j<Count;j++)
其它网友回答:
{
其它网友回答:
if(pData[j]<iTemp)
其它网友回答:
{
其它网友回答:
iTemp = pData[j];
其它网友回答:
iPos = j;
其它网友回答:
}
其它网友回答:
}
其它网友回答:
pData[iPos] = pData[i];
其它网友回答:
pData[i] = iTemp;
其它网友回答:
}
其它网友回答:
}
其它网友回答:
void main()
其它网友回答:
{
其它网友回答:
int data[] = {10,9,8,7,6,5,4};
其它网友回答:
SelectSort(data,7);
其它网友回答:
for (int i=0;i<7;i++)
其它网友回答:
cout<<data[i]<<" ";
其它网友回答:
cout<<"\n";}
其它网友回答: