/* Author: Marco T. Morazan Date: 2/3/2002 Course: CSAS 1112 */ import java.io.*; import java.util.StringTokenizer; public class IntListIO { /* PRE: infile points to a file that has at least n integers AND infile has only one integer per line AND n>=0 POST: return a LinkList containing the first n integers of infile. */ public static LinkList initIntList(BufferedReader infile, int n) throws IOException {LList sublist; Integer elem; //int k; if (n == 0) {return(new LinkList());} else { elem = read_int(infile); sublist = initIntList(infile, n-1); return(new LinkList(elem,sublist)); } } /* PRE: outfile points to an output file AND L is a LinkList Integer objects POST: The elements of L have been printed in order from the first to the last to outfile */ public static void outputIntList(java.io.PrintWriter outfile, LList L) throws IOException { LList lst; lst = L; while (!(lst.isEmpty())) { outfile.println(lst.car()); lst = lst.cdr(); } } /* PRE: infile points to a file of integers (one per line) POST: return an Integer Object with the value of the first unread integer in infile. */ public static Integer read_int(BufferedReader infile) throws IOException {Integer i; String s = infile.readLine(); StringTokenizer st = new StringTokenizer(s); i = new Integer(st.nextToken()); return i; } }