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