列出所有子集(字典顺序)
来源:互联网 发布:java同步方法 编辑:程序博客网 时间:2024/05/25 01:36
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 20
#define LOOP 1
void main(void)
{
int set[MAXSIZE];
int n, i;
int position;
char line[100];
printf("\nAll Possible Subsets Generation by Lexical Order");
printf("\n================================================");
printf("\n\nNumber of Elements in the Set --> ");
gets(line);
n = atoi(line);
printf("\n{}"); /* the empty set */
position = 0; /* start from the 1st pos. */
set[position] = 1; /* it gets a '1' */
while (LOOP) { /* loop until done... */
printf("\n{%d", set[0]); /* print one result */
for (i = 1; i <= position; i++)
printf(",%d", set[i]);
printf("}");
if (set[position] < n) { /* this pos. can be inc*/
set[position+1] = set[position] + 1; /* YES*/
position++; /* inc. next pos. */
}
else if (position != 0) /* NO, the 1st pos? */
set[--position]++; /* backup and increase */
else /* NO, the 1st pos and can */
break; /* not be inc. JOB DONE! */
}
}
- 列出所有子集(字典顺序)
- 每日一小练——按字典顺序列出所有子集
- 列出所有子集(格雷码顺序)
- 列出所有排列(字典顺序)
- 列出所有子集-----字典顺序 2013年1月14日
- 列出所有子集(二进制递增方式)
- 列出所有子集
- 集合所有子集,无字典顺序与有字典顺序的两种解法(C/OC)
- 每日一小练——按字典顺序列出所有排列
- 列出所有K个元素的子集
- 每日一小练——列出所有子集
- 列出{1,2,,,,n}的所有子集
- 列出一个集合的所有非空子集
- 列出所有子集----------2013年1月3日
- 列出所有子集(采用列出2进制数的方法)-------------2013年1月4日
- C语言名题精选百则:所有子集,字典子集,Gray子集
- 所有子集
- 列出所有K个元素的子集-----2013年1月26日
- 行为驱动开发之一,推广篇
- Google +1对搜索引擎优化的影响
- pageContext.request.contextPath
- Ajax异步访问远程服务并设置超时
- 手把手教你玩转SOCKET模型之重叠I/O篇
- 列出所有子集(字典顺序)
- (转)抽屉中关闭时默认显示一部分的内容
- 选中Edit控件中的文本
- vmware环境下的kgdb环境配置和模块调试示例 (1)
- 列出所有子集(格雷码顺序)
- GridView 的 onselectedindexchanged 方法
- Linux下用Apple的bonjour服务进行摄像机搜索
- 列出所有排列(旋转法)
- dwr下拉框默认值及保存选中的值