예제 #1
0
        public void print()
        {
            hashNode current = null;

            for (int i = 0; i < size; i++)
            {
                current = hashTable[i];
                while (current != null)
                {
                    Console.Write(current.key + ": " + current.word + " -> ");
                    current = current.next;
                }
                Console.WriteLine();
            }
        }
예제 #2
0
        public void insert(string word)
        {
            int key = word[0] - 97;//Value of "a" in ASCII table is 97, we want to create
            //an array with indexes from 0 to 25 (because we have 26 alphabet letters)
            hashNode hn = new hashNode(key, word);

            if (hashTable[key] == null)
            {
                hashTable[key] = hn;
            }
            else
            {
                hn.next        = hashTable[key];
                hashTable[key] = hn;
            }
        }
예제 #3
0
        public void check(string s)
        {
            int      a      = s[0] - 97;
            hashNode cursor = hashTable[a];
            bool     result = false;

            while (cursor != null)
            {
                if (cursor.word == s)
                {
                    result = true;
                    break;
                }
                cursor = cursor.next;
            }
            if (result)
            {
                Console.WriteLine("The word " + s + " is found in the dictionary");
            }
            else
            {
                Console.WriteLine("The word " + s + " is NOT found");
            }
        }
예제 #4
0
 public hashNode(int key, string word)
 {
     _key  = key;
     _word = word;
     _next = null;
 }