⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spellcheck.java

📁 Java写的部分数据结构源码
💻 JAVA
字号:
import java.io.*;class SpellCheck {    static int lineNum = 1;    static String s;    static int ch;    static void readWord(InputStream fIn) {        try {            while (true)                if (ch > -1 && !Character.isLetter((char)ch)) { // skip                      ch = fIn.read();                  // non-letters;                     if (ch == '\n')                          lineNum++;                }                else break;            if (ch == -1)                return;            s = "";            while (ch > -1 && Character.isLetter((char)ch)) {                s += Character.toUpperCase((char)ch);                ch = fIn.read();            }        } catch (IOException io) {            System.out.println("Problem with input.");        }    }    static public void main(String args[]) {        String fileName = "";        InputStream fIn, dictionary;        InputStreamReader isr = new InputStreamReader(System.in);        BufferedReader buffer = new BufferedReader(isr);        Trie trie = null;        try {            dictionary = new FileInputStream("dictionary");            readWord(dictionary);            trie = new Trie(s.toUpperCase());  // initialize root;            while (ch > -1) {                readWord(dictionary);                if (ch == -1)                     break;                trie.insert(s);            }            dictionary.close();        } catch(IOException io) {            System.err.println("Cannot open dictionary");        }        System.out.println("\nTrie sideview: ");        trie.sideView();        ch = ' ';        lineNum = 1;        try {            if (args.length == 0) {                 System.out.print("Enter a file name: ");                 fileName = buffer.readLine();                 fIn = new FileInputStream(fileName);            }            else {                 fIn = new FileInputStream(args[0]);                 fileName = args[0];            }            System.out.println("Misspelled words:");            while (true) {                 readWord(fIn);                 if (ch == -1)                     break;                 if (!trie.found(s))                     System.out.println(s + " on line " + lineNum);            }            fIn.close();        } catch(IOException io) {            System.err.println("Cannot open " + fileName);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -