格雷码的递归输出
来源:互联网 发布:时间管理软件 知乎 编辑:程序博客网 时间:2024/06/08 20:02
//第一种
#include <math.h>
#include "stdlib.h"#include "stdio.h"
void CreateGrayCode(int n,int x) //x初始值为0
{
if(x<pow(2,n))
{
int graycode=(x^(x>>1));
char buf[32];
printf("%032s\n",itoa(graycode,buf,2));
CreateGrayCode(n,x+1);
}
}
int main()
{
CreateGrayCode(10,0);
return 0;
}
//第二种
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
using namespace std;
vector<string> getGray(int n) {
// write code here
int N=pow(2,n);
static int i=0;
static vector<string> vc;
if(i<N)
{
char temp[256];
sprintf(temp,"%d",i^(i>>1));
vc.push_back(temp);
++i;
getGray(n);
}
return vc;
}
0 0
- 格雷码的递归输出
- 递归调用的输出顺序
- 字符串的排列,递归输出
- 【递归入门】组合的输出
- 【递归入门】组合的输出
- JAVA递归和非递归输出字符串的全排列
- 链表的建立、输出、非递归反转、递归反转
- 二叉树遍历输出的递归和非递归实现
- 递归复习,递归输出字符串的全排列
- 很小的程序,递归实现逆序输出
- 递归输出一组元素的排列组合方式
- 递归实现文件目录的输出
- 递归输出符合条件的组合
- 递归调用,输出5!的值
- 一个十分巧妙的递归,输出排列
- 递归输出数组中最大的数
- 链表的逆序输出 递归算法
- 递归输出符合条件的组合
- 算法
- ubuntu 14.04下安装firfox,chromium,chrome可用的flash
- unity警告“Tiled GPU perf. warning: RenderTexture color surface (0x0) was not cleared/discarded, doin”
- windbg常用命令
- Android最佳性能实践(一)——合理管理内存
- 格雷码的递归输出
- 关于iOS TDD&BDD的学习与使用
- 自动文摘系统中的ISTP会议划分问题研究
- ARRAYLIST VECTOR LINKEDLIST 区别与用法
- PHP操作MySQL数据库
- 实现一个日期选择插件
- 简易的Win32小球碰撞程序
- Tomcat设置最佳线程数总结
- 如果将来