forked from agamdua/AppSecAssignment1
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Pseudocode.txt
49 lines (47 loc) · 1.64 KB
/
Pseudocode.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fuction check_word(string word, hashmap hashtable[])
{
Set int bucket to the output of hash_function(word).
Set hashmap_t cursor equal to hashmap[bucket].
While cursor is not NULL:
If word equals cursor->word:
return True.
Set curosr to cursor->next.
Set int bucket to the output of hash_function(word).
Set hashmap_t cursor equal to hashmap[bucket].
While cursor is not NULL:
If lower_case(word) equals curosr->word:
return True.
Set curosr to cursor->next.
return False.
}
function load_dictionary(string dictionary, hashmap hashtable[])
{
Initialize all values in hash table to NULL.
Open dict_file from path stored in dictionary.
If dict_file is NULL:
return false.
While word in dict_file is not EOF (end of file):
Set hashmap_t new_node to a new node.
Set new_node->next to NULL.
Set new_node->word equal to word.
Set int bucket to hash_function(word).
if hashtable[bucket] is NULL:
Set hashtable[bucket] to new_node.
else:
Set new_node->next to hashtable[bucket].
Set hashtable[bucket] to new_node.
Close dict_file.
}
function check_words(file fp, hashmap hashtable[], string misspelled[])
{
Set int num_misspelled to 0.
While line in fp is not EOF (end of file):
Read the line.
Split the line on spaces.
For each word in line:
Remove punctuation from beginning and end of word.
If not check_word(word):
Append word to misspelled.
Increment num_misspelled.
Return num_misspelled.
}