Results 1 to 2 of 2
  1. #1
    akusa is offline Member
    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Default help with linked lists

    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

    Java Code:
    public class WordMeaning 
    {
        String theword;
        String def;
        WordMeaning(String t, String d)
        {
            theword = t;
            def = d;
        }
        String getword()
        {
            return theword;
        }
        String getdef()
        {
            return def;
        }
     
     
    }
    Java Code:
    public class WordMeaningNode 
    {
     
        WordMeaning word;
        WordMeaning next;
        WordMeaningNode(WordMeaning w)
        {
     
            word = w;
            next = null;
        }
    }
    Java Code:
    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

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: help with linked lists

    The error message says what was wrong with your code. The "next" attribute in the class WordMeaningNode is a type of WordMeaning. But you are trying to give it a type of WordMeaningNode.

Similar Threads

  1. Linked Lists
    By ashplusham in forum New To Java
    Replies: 3
    Last Post: 11-20-2012, 09:05 PM
  2. Linked Lists
    By Dee in forum New To Java
    Replies: 18
    Last Post: 02-02-2011, 04:14 AM
  3. Linked Lists
    By vendetta in forum New To Java
    Replies: 6
    Last Post: 01-26-2010, 09:23 AM
  4. Doubly Linked Lists
    By stevenson15 in forum New To Java
    Replies: 6
    Last Post: 04-21-2009, 01:35 PM
  5. question about linked lists
    By jkurth in forum Advanced Java
    Replies: 1
    Last Post: 11-11-2007, 09:33 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •