externalsortrun.java
来自「java版的数据结构的完全代码 免费提供了 学习数据结构的请下载」· Java 代码 · 共 52 行
JAVA
52 行
// Introduced in Chapter 17import java.util.Scanner;/** A run of lines used by the ExternalSort program. */public class ExternalSortRun { /** Number of lines left in this run, possibly an overestimate. */ private int count; /** The next available line, if any. */ private String next; /** The Scanner from which the lines are drawn. */ private Scanner scanner; /** Up to maxLength lines will be drawn from scanner. */ public ExternalSortRun(Scanner scanner, int maxLength) { count = maxLength; this.scanner = scanner; if (scanner.hasNext()) { next = scanner.nextLine(); } else { count = 0; } } /** Return true if there is another line in this run. */ public boolean hasNext() { return count > 0; } /** Return the next available line and advance the run. */ public String next() { String result = next; count--; if (count > 0) { if (scanner.hasNext()) { next = scanner.nextLine(); } else { count = 0; } } return result; } /** Return the next available line but do not advance the run. */ public String peek() { return next; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?