Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
この再帰コードの意味がわかりません。隣接する 2 つのノードの 2 つの値が同じかどうかをチェックしますか?
bool has_repeats(element_t *e) { if (e == NULL) return false; if (contains_value(e->next, e->val)) return true; return has_repeats(e->next); }
助けてくれてありがとう!
はい、あなたはあなた自身の質問に答えることによってあなたが話していることを知っています!現在のノードを次のノードでチェックします。それらが同じである場合は戻り、trueそうでない場合は再帰的に自分自身にコールバックしますreturn has_repeats(e->next);。
true
return has_repeats(e->next);
contains_value(x, y)実際に何をしているのかを知るのに役立つと思います。@Benがコメントしたように、contains_value(x,y)おそらくリスト内のすべての値をチェックします。
contains_value(x, y)
contains_value(x,y)