排列组合的排序问题 全排列的递归算法: Codetemplate <class Type>inline void Swap(Type &a,Type &b){ Type temp=a; a=b; b=temp;}void Perm(Type list[],int k,int m){ //产生list[k:m]的所有排列 if(k==m) { //只剩下1个元素 for(int i=0;i<m;i++) cout << list[i]; cout << endl; } else //还有多个元素待排列,递归产生排列 for(int i=k;i<m;i++) { Swap(list[k],list[i]); Perm(list,k+1,m); Swap(list[k],list[i]); }} 这个排序还是很经典的,以致于我们花了一节课的时间在研究该递归。 相关文章: 2022-01-16 2021-12-22 2022-01-26 2021-11-29 2018-09-04 2022-12-23 2021-08-03 2021-08-13