时间:2021-03-31 09:14:14 | 栏目:C代码 | 点击:次
void diffarr(int arr[],int n)
{
int sn=n,index,*ptr=arr;
int *pfrom=new int[sn];
for(int i=0;i<sn;i++)
*(pfrom+i) =i+1 ;
srand(time(0));
for(int k=0;k<sn;)
{
index=rand()% sn;
if(*(pfrom+index)!=0)
{ //从源数据pfrom取,每取一个将其置为0,直至pfrom中所有元素都为0
*(ptr+k)=pfrom[index];
pfrom[index]=0;
k++;
}
}
delete [] pfrom;
}