訂正 //iをpushしないとダメか
class 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;
}