gray code 格雷码 递归
2016-02-22 16:03
239 查看
格雷码
the n-1 bit code, with 0 prepended to each word, followd by the n-1 bit code in reverse order,
with 1 prepended to each word.
运行结果
the n-1 bit code, with 0 prepended to each word, followd by the n-1 bit code in reverse order,
with 1 prepended to each word.
public class GrayCode{ public static void gray(int n, String prefix) { if(n == 0) System.out.println(prefix); else { gray(n-1,prefix + "0"); yarg(n-1,prefix + "1"); } } public static void yarg(int n, String prefix) { if(n == 0) System.out.println(prefix); else { gray(n-1,prefix + "1"); yarg(n-1,prefix + "0"); } } public static void main(String[] args) { int N = Integer.parseInt(args[0]); gray(N, ""); } }
运行结果
> java GrayCode 3 000 001 011 010 110 111 101 100
相关文章推荐
- linux下网络程序遭遇SIGPIPE的解决(转)
- IMS (IP多媒体子系统)
- Android学习笔记-界面和数据存储以及一些零碎知识点
- 配置windows失败,还原更新,请勿关机
- Asp.net网站中 js通过input type="file" 上传文件
- Android-Tab
- Android-Tab
- vim 的使用方法
- VMware WorkStation9.0 安装centos-6.4
- linux命令sysctl使用
- 【20】AngularJS 参考手册
- 帅呆了!ASP.NET Core每秒能处理115万个请求
- app store 获取app信息
- 如何解决SpringMvc数据传输乱码问题
- C#自选字段条件报表
- POJ 3414 Pots(隐式图的遍历+记录路径)
- erlang xref使用记录
- ApplePay 实现代码片段
- 图像小波分析
- hdu 2054 A == B ? (java)