2013-10-29 实验之数组中元素全排列(递归思想题)
来源:互联网 发布:什么时候开始有的网络 编辑:程序博客网 时间:2024/05/19 19:59
实验描述:数组中元素全排列
注意事项:注意递归无出口,递归到最后一个自动返回,深度最后一层处理数组
应用程序:
#include<stdlib.h>#include<stdio.h>void execCombination(int *combArray, int index, int num, int depth){int i;int swap;for(i = index; i < num; i++){swap = combArray[index]; //swap each elementcombArray[index] = combArray[i];combArray[i] = swap;execCombination(combArray, index+1, num, depth+1);combArray[i] = combArray[index]; //restore the previous stationcombArray[index] = swap;}if(depth == num){int j;//save the array and do your logical codefor(j=0; j < num; j++){printf("%-4d ", combArray[j] );}printf("\n");}}int main(void){int num;printf("Please enter the length:");scanf("%d", &num);int *combArray = (int *)malloc(sizeof( int ) * num);int i;for(i=0; i < num;i++){combArray[i] = i+1;}execCombination(combArray, 0, num, 1);return 0;}
- 2013-10-29 实验之数组中元素全排列(递归思想题)
- 递归思想输出数组全排列
- 数组元素全排列(递归版本)
- 全排列递归思想
- 递归思想实现全排列
- 递归思想实现全排列
- 使用递归对数组元素进行全排列
- 递归实现元素全排列
- 递归之全排列
- 递归之全排列
- 递归之全排列
- 非递归数组全排列
- 递归实现数组全排列
- 数组全排列递归实现
- 数组元素的全排列
- 用递归的思想输出一个数组的全排列,和组合
- 递归算法之全排列
- 递归算法之全排列
- Noi2001 食物链
- Web分层设计研究(一)
- android Activity类中的finish()、onDestory()和System.exit(0) 三者的区别
- SVN简介
- Ural 1471. Tree
- 2013-10-29 实验之数组中元素全排列(递归思想题)
- MonetDB资料2
- w3school JS测验
- 查看oracle连接数
- 非常适合新手的长尾关键词挖掘方法
- hadoop2.0 遇到的问题 (持续更新)
- VCDebug、Ollydbg、WinDbg字符串条件断点设置方法总结
- 百度云推送客户端配置IOs
- ubuntu 下查看已安装程序