标签:out stream 选择 bsp str iostream 元素 ios mes
#include <iostream>
using namespace std;
//数组的前一个元素和后一个元素相比
void select_sort(int *p,int n)
{
int i, j, k, t;
for (i = 0; i < n - 1;i++)
{
k = i;
for (j = i + 1; j < n;j++)
if (*(p + j) < *(p + k))//从小到大
k = j; //用指针法访问数组元素
t = *(p + k); *(p + k) = *(p + i); *(p + i) = t;
}
}
int main()
{
int a[10], i;
cout << "请输入数组元素:" << endl;
for (i = 0; i <= 9; i++)
cin >> a[i];
cout << endl;
select_sort(a,10);
cout << "重新排序为:" << endl;
for (i = 0; i < 10; i++)
cout << a[i] << " ";
cout << endl;
return 0;
}
标签:out stream 选择 bsp str iostream 元素 ios mes
原文地址:http://www.cnblogs.com/rong123/p/7789191.html