-
Notifications
You must be signed in to change notification settings - Fork 1
/
wordset.h
137 lines (117 loc) · 4 KB
/
wordset.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* Crossword Assistant
* Assignment 2, COSC2085 Programming Techniques
* Copyright 2010 s3245848 Tran Van Trong, s3255132 Huynh Quang Dung
* RMIT International University Vietnam
* This assignment includes software developed by the above mentioned
* student(s.)
* Refer to the NOTICE file in the root of the source tree for
* acknowledgements of third party works used in this software.
*
* Date created: 18 Dec 2010
* Date last modified: 3 Jan 2011
*/
#ifndef WORD_SET
#define WORD_SET
#ifdef TYPE
#include TYPE
#else
#error TYPE must be defined with the quoted string header file name
#endif
/*
* WordSet
*
* WordSet is a data structure to store dictionary words
*
* type:
* WordSet
*
* constants:
* SUCCESS
* FAILURE
*
* interface routines:
* WordSet *MakeSet(WordSet *set, char sortType)
* attempts to initialise a WordSet variable (passed by address)
* if insufficient memory is available for the size list requested
* then MakeSet() retuns FAILURE, otherwise it returns SUCCESS
* MakeSet() must be applied to an WordSet before any other
* function.
*
* WordSet *Initialize(WordSet *set, char *fileName, char sortType)
* initialize a WordSet by inserting all the words in the specified
* file into a WordSet varialbe (passed by address). If the WordSet
* variable is not yet created, create it by calling MakeSet()
*
* int InsertWord(WordSet *set, char *word)
* insert a word into the a WordSet varialbe (passed by address),
* increase the size of the set by 1.
* Return SUCCESS if the word does not exist in the set, otherwise
* return FAILURE
*
* int RemoveWord(WordSet *set, char *word)
* remove a word from a WordSet varialbe (passed by address),
* decrease the size of the set by 1.
* Return SUCCESS if the word exists in the set, otherwise
* return FAILURE
*
* int SearchWord(WordSet *set, char *word)
* search for a specified key word in a WordSet varialbe (passed by address).
* Return SUCCESS if the word is found, otherwise FAILURE.
*
* void PMSearchWord(WordSet *set, char *keyword, char **result, int *rsize)
* partial match search, accept keyword with represent character '_'
* the results are stored in the array of string result, and the size
* of the result is stored in rsize
*
* int Size(WordSet *set)
* return the size of the set
*
* char SortType(WordSet *set)
* return the sort type of a WordSet varialbe (passed by address)
*
* void Display(WordSet *set)
* display all the words in a WordSet varialbe (passed by address)
* as the sort type specified
*
* void InOrderTraverse(WordSet *set, void (*poly)(char *key))
* traverse through a WordSet varialbe (passed by address) and
* process all the words ascendingly using poly method
*
* void PostOrderTraverse(WordSet *set, void (*poly)(char *key))
* traverse through a WordSet varialbe (passed by address) and
* process all the words descendingly using poly method
*
* void PreOrderTraverse(WordSet *set, void (*poly)(char *key));
* traverse through a WordSet varialbe (passed by address) and
* process all the words from root to left child then
* right child using poly method
*
* void FreeSet(WordSet *set)
* reset a WordSet variable (passed by address) to the "empty"
* state.
*
*
*/
typedef struct
{
WordNode *root;
char sortType;
int size;
} WordSet;
WordSet *MakeSet(WordSet *set, char sortType);
WordSet *Initialize(WordSet *set, char *fileName, char sortType);
int InsertWord(WordSet *set, char *word);
int RemoveWord(WordSet *set, char *word);
int SearchWord(WordSet *set, char *keyword);
void PMSearchWord(WordSet *set, char *keyword, char **result, int *rsize);
int Size(WordSet *set);
char SortType(WordSet *set);
void Display(WordSet *set);
#ifdef TST_NODE
void DisplayPreOrder(WordSet *set);
void DisplayPostOrder(WordSet *set);
void DisplayInOrder(WordSet *set);
#endif
void FreeSet(WordSet *set);
char *Trim(char *str);
#endif