全排列 数据结构(机工出版) 递归算法 有改动 还有不完善的地方!
来源:互联网 发布:什么是大数据交易平台 编辑:程序博客网 时间:2024/06/04 20:06
#include<iostream>
using namespace std;
void swap(int *x,int *y)
{
int temp=*x;
*x=*y;
*y=temp;
}
void perm(int *list,int i,int n)
{
int j,temp;
if(i==n)
{
for(j =0; j <= n; j++)
cout<<list[j]<<" ";
cout<<endl;
}
else
{
for(j=i;j<=n;j++)
{
swap(list[i],list[j]);
perm(list,i+1,n);
swap(list[i],list[j]);
}
}
}
int main()
{
int a[1010],n;
while(cin>>n)
{
for(int i=n;i<n;i++)
{
cin>>a[i];
}
perm(a,0,n-1);
}
return 0;
}
using namespace std;
void swap(int *x,int *y)
{
int temp=*x;
*x=*y;
*y=temp;
}
void perm(int *list,int i,int n)
{
int j,temp;
if(i==n)
{
for(j =0; j <= n; j++)
cout<<list[j]<<" ";
cout<<endl;
}
else
{
for(j=i;j<=n;j++)
{
swap(list[i],list[j]);
perm(list,i+1,n);
swap(list[i],list[j]);
}
}
}
int main()
{
int a[1010],n;
while(cin>>n)
{
for(int i=n;i<n;i++)
{
cin>>a[i];
}
perm(a,0,n-1);
}
return 0;
}
- 全排列 数据结构(机工出版) 递归算法 有改动 还有不完善的地方!
- 深度优先算法 演示,还有不完善的地方
- HDU_2222 大部分是别人的,有的地方稍有改动,代码有不完善的地方!
- 全排列的递归算法
- 全排列的递归算法
- 全排列的递归算法
- 全排列的递归算法!
- 全排列的递归算法
- 全排列的递归算法
- 全排列算法(递归)
- 全排列算法(递归)
- C++使用递归的方法生成全排列(《数据结构与算法》,学习笔记)
- 全排列的算法(七)——递归算法
- 全排列的简单递归方法(有重复元素和无重复元素的递归算法)
- 全排列递归算法
- 全排列递归算法
- 全排列算法-递归
- 全排列递归算法
- android monitor tool (8.0 监控文件系统 添加哪个进程修改文件功能)
- 高性能MySql进化论(五):提速Alter Table
- iOS error: No visible @interface for 'xxxx' declares the selector 'alloc'
- 计算机1-4班第01次作业思维总结
- 让C语言更高效
- 全排列 数据结构(机工出版) 递归算法 有改动 还有不完善的地方!
- Implement strStr() 实现strStr函数 @ LeetCode
- autohotkey +vba 利用文本文件传递数据
- 运维几个点
- java各种编码的解疑
- 1057. Stack
- tomcate
- 网络小测试
- eclipse利用jpcap getDeviceList 返回结果为null