遞回即使到達條件也不會停止
bool answer = trouverMot(tab, bankMots, x - 1, y, (longueurMatch 1), motNumero, positions1) |
trouverMot(tab, bankMots, x 1, y, (longueurMatch 1), motNumero, positions1) |
trouverMot(tab, bankMots, x, y - 1, (longueurMatch 1), motNumero, positions1) |
trouverMot(tab, bankMots, x, y 1, (longueurMatch 1), motNumero, positions1);
uj5u.com熱心網友回復:
如果我替換此代碼:
bool answer = trouverMot(tab, bankMots, x - 1, y, (longueurMatch 1), motNumero, positions1) |
trouverMot(tab, bankMots, x 1, y, (longueurMatch 1), motNumero, positions1) |
trouverMot(tab, bankMots, x, y - 1, (longueurMatch 1), motNumero, positions1) |
trouverMot(tab, bankMots, x, y 1, (longueurMatch 1), motNumero, positions1);
return answer;
和:
bool answer = trouverMot(tab, bankMots, x - 1, y, (longueurMatch 1), motNumero, positions1) ||
trouverMot(tab, bankMots, x 1, y, (longueurMatch 1), motNumero, positions1) ||
trouverMot(tab, bankMots, x, y - 1, (longueurMatch 1), motNumero, positions1) ||
trouverMot(tab, bankMots, x, y 1, (longueurMatch 1), motNumero, positions1);
return answer;
我得到了預期的輸出MANDOLINE。
我認為一旦你已經成功就不想遞回搜索(邏輯或運算子短路評估,按位或運算子沒有)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/439495.html
