Creating a program to read a text file full of words in alphabetical order. I then have to read it into a Linked List. The linked list should output total number of words, which I have managed to do. After this it needs to calculate the min and max depth and average look up, which are the parts i'm getting completely lost one, have been reading tutorials for hours. I need to some how add the count to the node each time it is called?
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Main;
//import InputWindow.InputWindow;
import EasyIn.*;
import EasyIn.EasyIn;
import java.io.*;
import java.util.*;
/**
*
* @author itmpm
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// int Row;
int Count;
int PrintCount;
// public list () {
StreamTokenizer st = new StreamTokenizer(new FileReader("filename"));
LinkedList linked = new LinkedList();
Iterator iterator;
while (st.ttype !=st.TT_EOF) {
st.nextToken();
if (st.ttype==st.TT_WORD)
// System.out.println(st.sval);
{int Row = 0;
if (Row == 0){
linked.addFirst(st.sval);
}
else
{
for(Count=0; ((Count<Row) && (st.sval == linked.get(Count))); Count++)
{
}
linked.add(Count, st.sval);
}
Row++;
iterator = linked.iterator();
PrintCount=0;
while (iterator.hasNext())
{
System.out.println(iterator.next());
PrintCount++;
}
}
iterator = linked.iterator();
PrintCount=0;
while (iterator.hasNext())
{
System.out.println(iterator.next());
PrintCount++;
}
System.out.println("End of Sorted Linked List!");
System.out.println("Size = " + linked.size());
// System.out.println(iterator.toString());
}}
}