I have some questions about Linked list. I understand the basic
concepts but need some help putting thoughts together, please.
The program should read info from the file which contains words and meaning
such as :
eat meaning1
go meaning2
It is a dictionary program which should be able to lookup the word and find
the meaning. My data structure is defined as below:
typdedef struct DTNtag
{ char data;
char* meaning;
struct DTNtag* otherLetter;
struct DTNtag* nextLevel;
} DictonaryTreeNode, *DictionaryTreeNodePtr;
We are not inserting a key and a value. Each node in my tree is
associated with a letter (and a possible meaning). Given a pointer to
a DTNode, I should be able to navigate thru the tree by looking at
the otherLetter field and the nextLevel field until you reach a
meaning (the meaning field). For example,
nodePtr
|
v
----- -----
|'a'| | 'i' |
| 1 | | 2 |
| ---->| 0 |
| | | | | |
--|-- --|--
| |
v v
----- -----
|'n' | | 't' |
| 3 | | 4 |
| 0 | | 0 |
| | | | 0 |
--|-- -----
|
v
-----
| 't' |
| 5 |
| 0 |
| 0 |
-----
1 -> "meaning for "a""
2 -> "meaning for "i""
3 -> "meaning for "an""
4 -> "meaning for "it""
5 -> "meaning for "ant""
These five nodes represent five words in our dictionary: "a", "an",
"ant", "i", "it".
Let's assume our user wants to add the word "and" to the dictionary.
After the call to addWord() our tree would look like this:
nodePtr
|
v
----- -----
|'a' | |'i' |
| 1 | | 2 |
| ------>| 0 |
| | | | | |
--|-- --|--
| |
v v
----- -----
|'n' | |'t' |
| 3 | | 4 |
| 0 | | 0 |
| | | | 0 |
--|-- -----
|
v
----- -----
|'d' | |'t' |
| 6 | | 5 |
| 0 | | 0 |
| 0 | | 0 |
----- -----
With 6 -> "meaning of "and""
Would you be able to help me with the following
functions? It's for read the file and search the word which has meaning. The meaning is also from the file.
DictionaryTreeNodePtr read(char* fileName);
char* lookup(DictionaryTreeNodePtr root, char* word);
thank you very much.