|
Before we begin inserting, should we set all fields of the Array of structs equal to "empty" or 0000000000 or whatever would be appropriate for the entry, or should we leave the array alone and begin entering data from scratch?There are lots of design details left to your choice. You don't even have to start with an empty directory. But, since insertion is one of the utilities, it seems most natural to me to start empty and insert whatever you would like to have in your test array. So now the question is how to represent the empty directory. You can use ``empty'' marks, but that reduces the robustness of the program in several ways. First, it requires you to reserve some code for ``empty,'' and nobody can have that code for a name (remember the artist formerly known as ``Prince'' and his attempt to use a glyph not in the alphabet for his name? :^). Second, it limits the ways that you can adapt the program to deal with changing directory sizes (increasing is probably more important, but perhaps you want to decrease size sometimes, too). So, I suggest that you keep a variable whose value is the current length of the directory, and ignore all entries beyond that length.
If we do set all the items to "empty", it would be easier to insert (we could test whether "name" == "empty"), but it would be less efficient in the begining.I don't see how ``empty'' marks make insertion any easier. All of the nonempty entries will cluster together, anyway. You'll still have to move entries around to insert.
I wouldn't want to lose points for efficiency.In this class, we are not interested in fine points of run-time efficiency. Some problems have natural gross efficiency goals: for example, it's silly to write a ``binary search'' program that doesn't achieve its results in time proportional to the logarithm of the directory size. But, once a program meets the basic goals, we are interested in elegance, robustness---in general in the efficiency of manipulating the program, rather than executing it. Mike O'D. |
to: