- オブジェクト指向なんて今すぐやめてください
432 :デフォルトの名無しさん[sage]:2014/05/11(日) 15:26:26.03 ID:DIiBgHNQ - >>424の例文は要するに再帰だね。Cで書き直すとこうなる。バッファオーバーフローすることをのぞけば大差ない。
int word_count(char* text) { return out(text, 0); } int out(const char* text, int count) { char c; if (!*text) reutrn count; c = *text++; if (!c) return count; if (!isspace(c)) in(text, count); return out(text, count); } int in(const char* text, int count) { char c = *text++; if (!c) { count++; return count; } if(isspace(c)) { count++; return count; } in(text, count); }
|