C++时间复杂度为O(n)随机生成不重复的数代码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#include<stdio.h>
#include <time.h>
#include "iostream"
#include <math.h>
#define  N  53
using namespace  std;
  
//print array
void display(int *a)
{
       for (int i =0;i<N;i++)
       {
           cout<<" "<<a[i]<<" ";
       }
         
}
  
int  main(void)
{
      
    int b[N],a[N];
    for (int i =0;i<N;i++)
    {
        b[i] = i+1;
    }
    //  random(a);
    srand((unsigned)time(NULL));
    int MaxIndex = N;
    for ( i= 0;i<N;i++)
    {
          
    // 
        int index = (int)rand()%MaxIndex;//随机一个 0 - 52的index
        a[i] = b[index];        //随机到的数字给a[i],i from 0 to N-1
        b[index] = b[MaxIndex-1];
        MaxIndex--;
      
    }
        display(a);
    return 0;
}