Re: [問題] 動態調整深度的迴圈(loop)

看板C_and_CPP作者 (我要加入劍道社!)時間16年前 (2009/10/29 11:31), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/7 (看更多)
void dyn_depth_loop(int max, int depth) { vector<int> counter(depth, 0); while(1){ // ... // function body // ... // increase the loop counter for(int i = 0; i < depth; ++i){ ++counter[i]; if(counter[i] < max){ // no need to carry // reset the counters of inner loops fill(&counter[0], &counter[i], counter[i]); break; } else { if(i == depth - 1) // reach the end return; } } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.29.108
文章代碼(AID): #1AwGo0-L (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1AwGo0-L (C_and_CPP)