Hi im really finding it hard to see what is wrong with my code. any help would be greatly appreciated.
It is for this project : project_3 - RW 144
import org.w3c.dom.Node;
public class LinkedList
{
private Node first;
Node last;
private class Node
{
Node next;
String Kgram;
int[] asci = new int[127];
int count =0;
}
LinkedList() // default constructor
{
first = new Node() ;
}
LinkedList(LinkedList l) // copy constructor
{
first = l.first;
}
private void check(String current,Node last )
{
char cchar = current.toString().charAt(0);
int iaski = ((int)cchar);
last.asci[iaski]++;
}
public void add(String kgram) // adds a kgram to the linked list if it already exists then it increments its count
{
String silly;
if (first.Kgram == null)
{
System.out.println("first added");
System.out.println(kgram);
first.Kgram = kgram;
last = first;
return;
}
for(Node x=first ;x != null;x=x.next)
{
silly = x.Kgram.toString();
if(silly.equals(kgram))
{
System.out.println("double");
System.out.println(kgram);
x.count++;
check(kgram, last);
last = x;
return;
}
if(x.next ==null)
{
System.out.println("single");
System.out.println(kgram);
Node newnode = new Node();
newnode.Kgram = kgram;
x.next = newnode;
check(kgram, x);
last = x.next;
}
}
}
void printList() // prints all the item of the list in order
{
char c ;
for(Node x = first; x!= null;x = x.next )
{
System.out.print(x.Kgram) ;
for(int i=0;i<127;i++)
{
if(x.asci[i]>0)
{
c = (char) i;
System.out.print("" + c + "" + x.asci[i]);
}
}
System.out.println();
}
}
public static void main(String [] args)
{
LinkedList l = new LinkedList();
l.add("aa");
l.add("ag");
l.add("ad");
l.add("ae");
l.add("af");
l.printList();
}
}