-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.c
More file actions
66 lines (48 loc) · 1.22 KB
/
dictionary.c
File metadata and controls
66 lines (48 loc) · 1.22 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include "tree.h"
#include "list.h"
#include "dictionary.h"
Dictionary DictionaryCreate(int size){
assert(size >= 1);
Dictionary d = (Dictionary) malloc(size * sizeof(ListNode));
assert(d != NULL);
// null every entry
for (int i = 0; i < size; i++){
d[i] = NULL;
}
return d;
}
// before destroying, the tree and list has been already free
// so only free the outermost structure is enough
Dictionary DictionaryDestroy(Dictionary d, int size){
assert (d != NULL);
free(d);
d = NULL;
return d;
}
ListNode DictionarySearch(Dictionary d, int c){
assert(d != NULL);
assert(c >= 0);
return d[c];
}
void DictionaryInsert(Dictionary d, ListNode listn){
assert(d != NULL);
assert(listn != NULL);
assert(listn->trn->c >= 0);
d[listn->trn->c] = listn;
return;
}
void DictionaryShow(Dictionary d, int c){
assert(d != NULL && c >= 1);
ListNode LN;
for (int i = 0; i < c; i++){
LN = DictionarySearch(d, i);
if (LN != NULL){
printf("For char %c %d: issymbol = %d\n", i, i, IsSymbolNode(LN->trn));
}
}
return;
}