《算法》学习过程中,在eclipse里调试时,对于官方提供的源码中标准输入的操作,没有搞懂
自己改了一下,直接读取本地测试数据测试数据可在http://algs4.cs.princeton.edu/code/下载 algs4-data.zip
如果各位如有直接调试官方代码的经验,还望留言,不胜感激!
//file1: TestDemo.java
package com.zs.mergeSort;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import com.zs.stdin.StdInNew;
public class TestDemo {
private static Scanner scanner = null;
private static String inputFilePath = "C:\\Users\\joshuai\\Desktop\\algs4-data\\";
private static String inputFileName = "tinasdfy.txt";
public static void main(String args[]) {
try {
scanner = new Scanner(new File(inputFilePath + inputFileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
StdInNew stdInNew = new StdInNew(scanner);
String[] a = stdInNew.readAllStrings();
Merge merge = new Merge();
merge.sort(a);
merge.show(a);
}
}
file2: Merge.java
参考《算法》的官网
http://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/Merge.java.html
file3: StdInNew.java
参考《算法》的官网,下载algs4.jar,导入jar包,参考StdIn.class即可