#include<iostream>
using namespace std;
const int total_size = 20;
void sample_array(int a[], int&i);
void swapvalues(int&a, int&b);
int small_est(int a[], int size_used,int&index);
void main()
{
 int b[total_size], n,m;
 sample_array(b, n);//n为实际的长度
 for (int i = 0; i < n-1; i++)
 {
 
 
 m = small_est(b, n,i);
 swapvalues(b[i], b[m]);
 }
 for (int j = 0; j < n-1; j++)
 {
 cout << b[j] << "<";
 
 }
system("pause");
}
void sample_array(int a[],int&i) //输入数字放入数组中,i为数组实际长度
{
 int next;
 i = 0;
 cout<<"please input a series of numbers "<<endl<<"end up the input with a negtive number" << endl;
 cin >> next;
 
 do {
 a[i] = next;
 i++;
 cin >> next;
 } while (next >= 0);
void swapvalues(int&a,int&b)//交换两个数字
{ 
 int c;
 c = a;
 a = b;
 b = c;
}
int small_est(int a[],int size_used,int&index) //返回最小数的数字的下标
{
 int min,u=index;
 min = a[index];
 for (; index <=size_used-1; index++)
 {
 if (min > a[index])
 {
 min = a[index];
 u=index;
 }
 }
 return u;
}
m=small_est(b,n,i) 改为 m=small_est(b,n--,i)
不行哦
命名成了啥,不要养成不好习惯。
int a[]明显有性能问题,需要拷贝构造
回去好好学习
int small_est(int a[],int size_used,int&index) //返回最小数的数字的下标
最后一个参数不要用引用。
void sample_array(int a[],int&i) //输入数字放入数组中,i为数组实际长度
有可能越界。