小编tgl*_*ger的帖子

为什么/我在哪里陷入无限循环

我目前正在尝试获取文本文件,并将文本文件分解为单词.然后我尝试将每个单词存储为二叉树中的节点.这样做后,我也尝试打印二叉树.出于某种原因,当我运行我的代码时,我现在陷入无限循环,但我不明白在哪里或为什么这是如果你可以看到我被抓到哪里将是一个很大的帮助谢谢

public class Tester {

public static void main(String[] args) throws FileNotFoundException {

    Tester run = new Tester();
    run.it();

}

public void it() throws FileNotFoundException { 

    BTree theTree = new BTree();

    String str = this.readInFile();

    int position = 0;

    String newWord = this.breakIntoWords(str, position);

    while(newWord != null){

        theTree.add(newWord);

        newWord = this.breakIntoWords(str, position);

    }

    theTree.print();

}

public String readInFile() throws FileNotFoundException {


    String myFile = "";
    int numWords = 0;

    Scanner myScan = new Scanner(new File("Dracula.txt"));

    while(myScan.hasNext() == true) {

        myFile …
Run Code Online (Sandbox Code Playgroud)

java binary-tree infinite-loop

0
推荐指数
1
解决办法
91
查看次数

标签 统计

binary-tree ×1

infinite-loop ×1

java ×1