CS113--Fall 96 HW9 FAQ Q. What do you mean by the table is full? Does it relate to the tree being full as a full-binary-search-tree? A. in some implementations, the tree can get full (if you use an array for example, once the array is full you can't put in any more items.) for the bst implementation, you could try to allocate some piece of memory a bit bigger than one node in the tree. if it succeeds, the free the memory again and return true. if it fails, there is not enough memory to allocate a new node. this assumes that the client will be checking for a full table just before trying to insert. (if the client waits, other things may use up the memory in the mean time.) Q. Can I use a global variable in hw9? A. this is probably not a good idea, but i am not sure what you have in mind. it is generally bad practice to use globals (especially when avoidable) but we have seen a couple of examples where they are useful and necessary. an idea occured to me, do you want your instances of visit to communicate via a global variable? this can probably be avoided. or consider a static local variable inside the visit function. a static local variable has local scope (just available to the function where it is declared) but its lifetime is the life of the program. each time the function is called, the old value (from the last call) is "remembered". for example, this dumb function counts how often it is called and returns the value, but does nothing else. int dumb(void){ static int count = 0; count++; return count; } you would likely need your function to resent its static variable values when it received some special input (like an empty word) if you want such a thing to work more than once in a run of the program. be sure to provide initial values for the static variables. Q. And can I assume that there is no more than 50, 100, or some number of common frequent words in the command "-c "? A. such an implementation would be better than none, but not as good as one without restrictions. if you do have some upper bound, make it a #defined constant, so that your program could easily be modified to make the bound different and so that your code reads nicely. Q. Is there an easy and quick way to read words into the table? Since the words does not include punctuation and hyphens etc., we can not use fscanf to read a string. Because of that we must read each character at a time and put it into the string if it is a letter. A. look at page 541 -- 543 for some discussion of this. scanf has a format string which looks like %[ list of chars ] and tells scanf (and fscanf) to read as long as the characters come from the list of chars. for example, to read digits you could use %[0123456789]%c and scanf would read in characters until the first non-didgit and store the value in a string, then read the next character (not a digit) and store it in a character. reading the data one character at a time is also acceptable. or you can read a line at a time, storing it in a string, and then divide up the string. whichever method you choose, be sure you can handle the end of the file nicely, regardless of whether the last character (before EOF) in the file is part of a word or not. Q. Can we use functions from other libraries? Particularly, the strlib library contains functions that are very useful such as StringCompare and ConvertToLowerCase. Can we use these functions or do you want us to write our own version? A. you may use the libraries.