- なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
296 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 08:26:09.58 ID:u3wwvrmv - これは、俺は再帰的だと読むけど、お前らはループ的だと読むのか?
class tree{ public: tree* parent;//rootのparentはnullptr tree* chlid[];//説明の便宜上 int childsize; ... }; //終了検知 bool end(tree* root, tree* v, int i, bool& b){ return ((b || !v->childsize) && v == root && v->childsize <= i) } //次の順番のノードを返す tree* next(tree* v, int i, bool& b){ if(v->childsize <= i) { b = true; return v->parent; } return v->child[i]; } //ノード処理 tree* nodefunc(tree* root, tree* v) { int i = 0; bool b = false; while(!end(root, v, i, b)){ i += 1; b = false; v = next(v, i ,b); if(!b){//v:子ノード処理} else{//v:親ノード処理} } }
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
297 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 08:30:01.75 ID:u3wwvrmv - //iの順番のノードを返す
tree* ith_child(tree* v, int i, bool& b){ if(v->childsize <= i) { b = true; return v->parent; } return v->child[i]; } //ノード処理 tree* nodefunc(tree* root, tree* v) { int i = 0; bool b = false; while(!end(root, v, i, b)){ i += 1; //次のノード b = false; v = ith_child(v, i ,b); if(!b){//v:子ノード処理} else{//v:親ノード処理} } }
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
298 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 08:35:55.80 ID:u3wwvrmv - 訂正
class tree{ public: tree* parent;//rootのparentはnullptr tree* chlid[];//説明の便宜上 int childsize; ... }; //終了検知 bool end(tree* root, tree* v, int i, bool& b){ return ((b || !v->childsize) && v == root && v->childsize <= i) } //iの順番のノードを返す tree* ith_child(tree* v, int i, bool& b){ if(v->childsize <= i) { b = true; return v->parent; } return v->child[i]; } //ノード処理 tree* nodefunc(tree* root, tree* v) { int i = 0; bool b = false; //最初のノード処理 while(!end(root, v, i, b)){ i += 1; //次のノード b = false; v = ith_child(v, i ,b); if(!b){//v:子ノード処理} else{//v:親ノード処理} } return v; }
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
299 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 08:42:22.01 ID:u3wwvrmv - 訂正
class tree{ public: tree* parent;//rootのparentはnullptr tree* chlid[];//説明の便宜上 int childsize; ... }; //終了検知 bool end(tree* root, tree* v, int i, bool& b){ return ((b || !v->childsize) && v == root && (i < 0 || v->childsize <= i)) } //iの順番のノードを返す tree* at(tree* v, int i, bool& b){ if(i < 0 || v->childsize <= i) { b = true; return v->parent; } return v->child[i]; } //ノード処理 tree* nodefunc(tree* root, tree* v) { int i = 0; bool b = false; //最初のノード処理 while(!end(root, v, i, b)){ i += 1; //次のノード b = false; v = at(v, i ,b); if(!b){//v:子ノード処理} else{//v:親ノード処理} } return v; }
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
300 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 08:53:36.58 ID:u3wwvrmv - 訂正 //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; }
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
304 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 09:18:51.51 ID:u3wwvrmv - コンパイラ通してないからミスばっかしでゴメン
//root以下のノード処理 tree* nodefunc(tree* root) { crntzero(root);//root以下のcrntを全てゼロ初期化処理:詳細は省略 tree* v = root; bool b = false; //最初のノード処理 while(!v->end(root, b)){ v->crnt += 1; //次のノード b = false; v = v->crntchild(b); if(!b){//v:子ノード処理} else{//v:親ノード処理} } return v; }
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
305 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 09:21:14.87 ID:u3wwvrmv - >>303
再帰関数は使ってないけど、処理自体は再帰的処理そのものだよ
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
317 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 09:29:10.11 ID:u3wwvrmv - こういう処理は
ループ的に説明するより、再帰的に説明した方が 分かりやすいんだけど
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
322 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 09:40:00.52 ID:u3wwvrmv - >>306-316、は妨害、↓は再帰的に処理を説明した方がいい
class tree{ public: tree* parent;//rootのparentはnullptr tree* chlid[];//説明の便宜上 int childsize; int crnt;//子ノード指示変数 ... //終了検知 bool end(tree* root, bool b){ return ((b || !childsize) && this == root && (crnt < 0 || childsize <= crnt)) } //crntの順番のノードを返す tree* crntchild(bool& b){ if(crnt < 0 || childsize <= crnt) { b = true; return parent; } return child[crnt]; } }; //root以下のノード処理 void nodefunc(tree* root) { crntzero(root);//root以下のcrntを全てゼロ初期化処理:詳細は省略 tree* v = root; bool b = false; //最初のノード処理 while(!v->end(root, b)){ v->crnt += 1; //次のノード b = false; v = v->crntchild(b); if(!b){//v:子ノード処理} else{//v:親ノード処理} } }
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
325 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 09:54:18.33 ID:u3wwvrmv - 再帰関数のみが再帰的って言っている奴が発狂したか。。。
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
329 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 12:36:32.11 ID:u3wwvrmv - >おまえら、マジで精神病と思われる宣言的絶対主義の形而上学バカの一味は人類の公的な敵だとおもっているからな。
まるで自分が人類の唯一の味方かのような書き込みですね
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
330 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 12:59:14.49 ID:u3wwvrmv - >>287
で、人類唯一の味方のお前は、何でツリートラバースが 再帰的処理をラッピングして、列挙しているとは思わないの? >>322 のような処理ならば ループ的に説明するより、再帰的に説明した方が話が通る
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
331 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 14:00:59.20 ID:u3wwvrmv - >宣言的絶対主義の形而上学
が、そんなに嫌なら 「基準を全く用いないこと」 で、何かの意味が分かりますか?
| - なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
332 :NAS6 ◆n3AmnVhjwc []:2015/09/12(土) 14:26:26.36 ID:u3wwvrmv - x数列上に、dxを決めつけない限りは、いかなる論議もできません
|
|