Hi I Need Help With This Study Guide Question From My Computer Science Class(Programming In C)

0 Comment

3. We can use a binary search tree to keep track the word frequencies in a text. The convention
is that the left branch holds lexicographically smaller words, and the right larger. Your task
is to implement addWord (). If the word exists in the tree, you should increment its count. If
it is a new word, you should allocate a new tree node, allocate enough memory to store the
word, make a copy of it, set its count to 1, and insert the new node in the proper place.
Additionally, draw the tree after the words from Gettysburg are added.
char *Gettysburg = { quot;governmentquot;, quot;ofquot;, quot;thequot;, quot;peoplequot;,
quot;byquot;, quot;thequot;, quot;peoplequot;, quot;forquot;, quot;thequot;, quot;peoplequot;,
quot;shallquot;, quot;notquot;, quot;perishquot;, quot;fromquot;, quot;thequot;, quot;earthquot; };
typedef struct tree {
char *word;
int count;
struct tree *left, *right;
} Tree;
Tree *addWord (Tree *ptr, const char word ) {
Tree root = NULL;
for (int i = 0; i lt; 16; i++)
root = addWord(root, Gettysburg[i] );Engineering Technology