排序问题,
// rand.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "iostream"
#include "time.h"
#include<stdlib.h>
using namespace std;
class pac
{
public:
int lim;
pac(int a)
{
lim = a;
}
pac(){}
int obj1()
{
return 1+(int)(10*rand())/(RAND_MAX+1);
}//加入的值函数
int obj2()
{
int a = 34567;
return a;
}//固定值
int add()
{
return lim;
}//提供加入
int show()
{
return lim;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
pac load;
int a[10] = {0,1,2,3,4,5,6,7,8,9};
int tmp;
srand((int)time(0));
for(int i = 0;i<5;i++)
{
int xu = load.obj1();
if(xu<i)
tmp = a[xu];
a[xu] = a[i];
a[i] = tmp;
cout<<load.obj1();
}
cout<<endl;
cout<<load.obj2();
return 0;
}
大家帮忙看看在main函数里面为什么排序步成功?谢谢高手赐教