我一直在尝试通过使用二叉树来建立morsecode的结构来建立翻译器。重新执行该方法时,我始终收到堆栈溢出错误
private String decode(String pCode, BinaryTree<String> pTree)
{
int loop1 = 0;
int loop2 = 0;
BinaryTree<String> tree = morsetree;
if (!pCode.isEmpty())
{
if (loop2 <= pCode.length())
{
while (pCode.substring(loop, loop+1) == " ")
{
loop2++;
}
}
if (loop2 > 5)
{
return null;
}
for (int i=0;i<loop2;i++)
{
if (pCode.substring(i, i+1) == "-")
{
tree = tree.getRightTree();
}
else
{
tree = tree.getLeftTree();
}
}
System.out.println(tree.getContent());
return getLetter(pCode.substring(loop2, pCode.length())
,morsetree);
}
return null;
}
Havent阅读了全部代码,但仅此部分似乎有问题。
while (pCode.substring(loop, loop+1) == " ")
{
loop2++;
}
“循环”在哪里定义?您如何确保while循环结束?循环运行后,条件似乎不会产生不同的结果