I'm trying to make a dictionary program using linked lists. I need four classes, one that holds the word and the meaning. One that creates the node of information and its link field. Another class that creates and maintains a linked list of words and their meanings. And then a test class.

so far I have

public class WordMeaning 
{
    String theword;
    String def;
    WordMeaning(String t, String d)
    {
        theword = t;
        def = d;
    }
    String getword()
    {
        return theword;
    }
    String getdef()
    {
        return def;
    }


}



public class WordMeaningNode 
{

    WordMeaning word;
    WordMeaning next;
    WordMeaningNode(WordMeaning w)
    {

        word = w;
        next = null;
    }
}



public class WordList 
{
    WordMeaningNode list;
    WordList()
    {
        list = null;
    }

    void add(WordMeaning a)
    {
        WordMeaningNode temp = new WordMeaningNode(a);
        temp.next = list;
        list = temp;
    }

    void add2(WordMeaning a2) //appending to a list
    {
        WordMeaningNode temp = new WordMeaningNode(a2);
        if (listIsEmpty())
        {
            list = temp;
        }
        else
        {
            WordMeaningNode curr = list;
            while(curr.next != null)
            {
                curr = curr.next;
            }
            curr.next = temp;
        }
    }

    boolean listIsEmpty()
    {
        boolean empty;
        if(list == null)
        {
            empty = true;
        }       
        else
        {
            empty = false;
        }


        return empty;
    }





}

These lines in the wordlist class are giving me errors.
temp.next = list;
curr = curr.next;
curr.next = temp;

says incompatible types
required: WordMeaning
found: WordMeaningNode

public class WordMeaningNode {
   WordMeaning word;
   WordMeaning next;

You are getting confused between WordMeaning and WordMeaningNode. A WordMeaning is some info about a word, a WordMeaningNode is an entry in linked list (that happens to include a WordMeaning as its data).
So in the code above, one of those two variables is incorrectly declared.

This article has been dead for over six months. Start a new discussion instead.