Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * dictionary.c
- *
- * Computer Science 50
- * Problem Set 5
- *
- * Implements a dictionary's functionality.
- */
- #include <stdbool.h>
- #include "dictionary.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- //alpha + "'"
- #define alphabet 27
- //create nodes
- typedef struct _node
- {
- bool is_word;
- struct _node* children[alphabet];
- }
- node;
- void freenode(node* leaf);
- node* root;
- unsigned int dic_size = 0;
- /**
- * Returns true if word is in dictionary else false.
- */
- bool check(const char* word)
- {
- node* leaf = root;
- for (int i = 0, n = strlen(word); i < n; i++)
- {
- int alphaplace2 = tolower(word[i]) - 'a';
- if (word[i] == '\'')
- {
- alphaplace2 = 26;
- }
- if (leaf->children[alphaplace2] != NULL)
- {
- leaf = leaf->children[alphaplace2];
- if (leaf->is_word == true)
- {
- return true;
- }
- }
- else
- {
- return false;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement