Gray Code
1 //reference http://blog.csdn.net/fightforyourdream/article/details/14517973 2 vector<int> grayCode(int n) { 3 vector<int> codes; 4 if(n<0) 5 return codes; 6 int size=1<<n;//相当于2的n次方 7 int i,tmp; 8 for(i=0;i<size;++i) 9 { 10 tmp=i^i>>1; 11 codes.push_back(tmp); 12 } 13 return codes; 14 }
posted on 2014-03-22 17:35 crane_practice 阅读(126) 评论(0) 编辑 收藏 举报