Hello so i was unable to complete my assignment because I had difficulties figuring out how to set up the search method within my linked list.. Now I still want to learn how to configure the linked list and i cant make any of the other methods such as remove, or replace if i cant figure out the search method. for some reason my results keep turning out null This is what i have so far..
public class WordList {
private WordMeaningNode list;
WordList()
{
list = null;
}
void add(WordMeaning b)
{
WordMeaningNode temp = new WordMeaningNode(b);
try
{
temp.Next = list;
list = temp;
}
catch(NullPointerException e)
{
System.out.println("Null Pointer Exception");
}
}
public String toString()
{
String result="";
WordMeaningNode current = list;
while (current != null)
{
result += current.Words.word + " - " + current.Words.meaning + "\n";
current = current.Next;
}
return result;
}
public WordMeaning findword (WordMeaning Word)
{
WordMeaningNode Checker = new WordMeaningNode(Word);
boolean found = false;
if (list.isEmpty() == true)
{
return null;
}
else
{
while(list.Next != null && !found)
{
if(list.Words.word.compareTo(Checker.Words.word)== 0)
{
found = true;
}
else
{
list = list.Next;
found = false;
}
}
}
if(found == true)
{
return list.Words;
}
else
{
return null;
}
}
listinside your findword method. ou shouldn't do that. You should also read the Java naming conventions and stick to them.list.Next != nulltolist != null