なあ、再帰関数好きな人いる? パート2 [転載禁止]©5ch.io
■ このスレッドは過去ログ倉庫に格納されています
0300NAS6 ◆n3AmnVhjwc
2015/09/12(土) 08:53:36.58ID:u3wwvrmvclass tree{
public:
tree* parent;//rootのparentはnullptr
tree* chlid[];//説明の便宜上
int childsize;
int crnt;//i
...
};
//終了検知
bool end(tree* root, tree* v, bool& b){
return ((b || !v->childsize) && v == root && (v->crnt < 0 || v->childsize <= v->crnt))
}
//crntの順番のノードを返す
tree* at(tree* v, bool& b){
if(v->crnt < 0 || v->childsize <= v->crnt) { b = true; return v->parent; }
return v->child[v->crnt];
}
//ノード処理
tree* nodefunc(tree* root, tree* v)
{
crntzero();//v以下のcrntを全てゼロ初期化処理:詳細は省略
bool b = false;
//最初のノード処理
while(!end(root, v, b)){
v->crnt += 1; //次のノード b = false;
v = at(v, b);
if(!b){//v:子ノード処理}
else{//v:親ノード処理}
}
return v;
}
■ このスレッドは過去ログ倉庫に格納されています