This discussion is archived
1 2 Previous Next 19 Replies Latest reply: Oct 28, 2012 6:09 PM by EJP Go to original post RSS
  • 15. Re: Table ADT with a Hash Table
    800282 Newbie
    Currently Being Moderated
    I don't quite get how a Table differs from the LL.
    I've inserted the words into the LL, so how do I
    implement this LL into a Table ADT?
    Here's a small start:
    public class MyTable {
    
        private MyLinkedList words;
        
        public MyTable() {
            words = new MyLinkedList();
        }
        
        public void insert(String word) {
            WordOccurrence newWord = new WordOccurrence(word);
            
            if(words.contains(newWord)) {          // If the word already exists in your word-list
                WordOccurrence existingWord = ...  // Get the reference of that existing word
                existingWord.increase();           // Increase the occurrence of the existing word
            }
            else {                                 // The new word does not exist in your word-list yet
                words.add(newWord);                // Add it to your word-list
            }
        }
        
        public static void main(String[] args) {
            MyTable table = new MyTable();
            table.insert("Dog");   // this should trigger the else-statement in the insert() method
            table.insert("House"); // this should trigger the else-statement in the insert() method as well
            table.insert("Dog");   // ! this should trigger the if-statement in the insert() method
        }
    }
    Your table should now have a linked list which looks like this:
    +-------+     -------
    |  Dog  |     | House |
    |       | --> |       | --> end of your list
    |   2   |     |   1   |
    -------     -------
  • 16. Re: Table ADT with a Hash Table
    807599 Newbie
    Currently Being Moderated
    What is the WordOccurrence class that "gets the reference of that existing word"? I am really sorry that I am asking many questions, but our prof does not explain well. Most of the students in class are doing quite poorly.
  • 17. Re: Table ADT with a Hash Table
    800282 Newbie
    Currently Being Moderated
    What is the WordOccurrence class that "gets the
    reference of that existing word"?
    See reply 9 for the class.
    Let's say you only added 1 Dog and after that 1 House .
    The list in your table class now looks like this:
    +-------+     -------
    |  Dog  |     | House |
    |       | --> |       | --> end of your list
    |   1   |     |   1   |
    -------     -------
    The next time you want to add the word Dog, using your insert method, the contains-method from your list class will return true. This means there is already a word Dog in the list. So we want to get the object (the WordOccurrence object) which holds the word Dog and increase it's occurrence with 1. You should be able to get a certain node in your list with some sort of a get-method from your LinkedList class.
    After that your list looks like this:
    +-------+     -------
    |  Dog  |     | House |
    |       | --> |       | --> end of your list
    |   2   |     |   1   |
    -------     -------
    This is the best I can explain things on a public forum (without just making your homework).
    If you are still unable to make some progress, I suggest teaming up with some class mates and/or ask the prof for clarification.

    Good luck.
  • 18. Re: Table ADT with a Hash Table
    971106 Newbie
    Currently Being Moderated
    Hello....I am doing this same program......can you email me your code at *[removed by moderator]*

    Edited by: EJP on 29/10/2012 12:07
  • 19. Re: Table ADT with a Hash Table
    EJP Guru
    Currently Being Moderated
    No he can't. He's been gone for five years, and it is not the purpose of this site to enable cheating and fraudulent imposture. Locking the thread.
1 2 Previous Next