Re: [問題]請問一下有什麼好方法可以找出gray code
※ 引述《Festung (die Festung Iserlon)》之銘言:
: 這種問題是Combinatorial Generation產生組合的問題的一種,
: 你可以在Frank Ruskey's Combinatorial Generation Resources網站,
: 找到這類的演算法與程式碼。
: http://www.cs.sunysb.edu/~algorith/implement/ruskey/implement.shtml
: 在此把產生Gray Code的範例程式貼於下供您參考:
太麻煩了....
//代入初始的 Pattern(可以直接代零), 和長度(Bits數)
void grayCode(unsigned int pattern, unsigned int size)
{
unsigned int i=0, mask, digital;
mask = 1<<size-1;
while(i<1<<size)
{
// 重點在這行...
mask = i^(i>>1);
// 把 GrayCode 印出來
for(digital=1<<(size-1); digital; digital>>=1)
printf("%d", (digital & (mask ^ pattern)? 1:0));
printf("\n");
i++;
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.250.193.10
※ 編輯: TroyLee 來自: 60.250.193.10 (11/14 02:09)
→
11/14 08:02, , 1F
11/14 08:02, 1F
→
11/14 21:59, , 2F
11/14 21:59, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):