// a constant for infinity and negative infinity
public static final int INF = java.lang.Integer.MAX_VALUE;
public static final int NEGINF = java.lang.Integer.MIN_VALUE;
// To generate a coin flip
// At the top of your skiplist class you need
import java.util.*;
// As one of your skiplist class instance variables include
java.util.Random randseq;
// In your skiplist constructor include:
randseq = new java.util.Random();
// A method to simulate a coin that is heads with probability 1/4
boolean coinFlip() {
return (randseq.nextInt(4) == 0);
}
// Here's some code that can be used to read either of the events
// file. Below has allEvents but you can change that to 20events.
// You'll have to add the calls to your skiplist and hashtable as
// needed.
BufferedReader r;
// Create a reader for the file
//
try {
InputStream is = new FileInputStream("allEvents");
r = new BufferedReader(new InputStreamReader(is));
}
catch (IOException e) {
System.out.println("IOException while opening " + e);
return;
}
// Parse each line of the file sequentially
//
try {
boolean stop = false;
while (!stop){
String nextline = r.readLine();
if (nextline == null) // end of file
stop = true;
else {
int tabLoc = nextline.indexOf('\t');
String tempDate = nextline.substring(0,tabLoc);
int date = Integer.parseInt(tempDate);
String description = nextline.substring(tabLoc+1,nextline.length());
// do something with the date and description beforing moving on
}
}
}
catch (IOException e) {
System.out.println("IOException while reading" + e);
}
// Here's how to use the StringTokenizer to parse the description into words
// which is useful for Part 5.
StringTokenizer st = new StringTokenizer(description.toLowerCase());
while (st.hasMoreTokens()){
String word = st.nextToken();
// do whatever you want with each word here
}