#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
using namespace std;
int ashuffle(int *a,int L)//将一个有L个整形数的数组随机重排
{
// int xh[L];
int * xh = new int[L];
for(int i=0;i<L;i++)
{
xh[i]=-1;
}
srand( (unsigned)time(NULL) );
for(int i=0;i<L;i++)
{
//srand((unsigned int)time(NULL));
//srand((unsigned int)time(NULL));
// Sleep(1000);
int x=rand()%L;
// x--;
// randomize();
// int x=random(L+1);
// x--;
while(1)
{
if(xh[x]!=-1)
x=(x+1)%L;
else
break;
}
xh[x]=i;
}
// int b[L];
int *b = new int[L];
for(int i=0;i<L;i++)
{
b[i]=a[i];
}
for(int i=0;i<L;i++)
{
a[xh[i]]=b[i];
}
delete [] b;
delete [] xh;
return 1;
}
int main(int argc, char *argv[])
{
int A[20];
for(int i=0;i<20;i++)
{
A[i]=i+1;
}
ashuffle(A,20);
for(int i=0;i<20;i++)
{
cout<<A[i]<<" ";
}
system("PAUSE");
return 0;
}
奇怪 编译没有报错 而且也能运行 我的内存阿