template<typename T> void swap(T* a, T* b) { T temp = *a; *a = *b; *b = temp; } //数组的全排列 void perm(int list[], int k, int m) { if (k==m) { copy(list,list+m,ostream_iterator<int>(cout," ")); cout<<endl; return; } for (int i=k; i<m; i++) { if(list[k] == list[i] && k != i) continue; swap(&list[k],&list[i]); perm(list,k+1,m); swap(&list[k],&list[i]); } }
void knuth(int n, int m)数组
{函数
srand((unsigned int)time(0));spa
for (int i=0; i<n; i++)blog
{it
if (rand()%(n-i)<m)io
{class
cout<<i<<endl;stream
--m;im
}di
}
}
如下prim函数的功能是分解质因数。请填空
void prim(int m, int n)
{
if (m>n)
{
while ( ) n++;
;
prim(m,n);
cout<<n<<endl;
}
}
分别为:m%n 和 m/=n