The code I reviewed is the word search code from 12061167 Lin xupeng.
The main method of the code is to traverse the path directory under the command line. If the file meets the suffix requirements, read the file content and follow the mode (0, 1 or 2) add the content to the Word Table and sort the output according to requirements; if the directory is a directory file, recursively open the directory file and check whether each file meets the requirements. Then, add the following words to the files according to the mode type and sort them in Lexicographic Order and output them.
In terms of function, the code can extract words that meet the requirements based on the mode Value and sort and output them to the specified file according to the first frequency and then the Lexicographic Order, but there are also some shortcomings:
1. in the definition of wordlib, after the constructor is executed, the system allocates 10000000 space to the strings of SS, words, twoword, sthrwords, and deli names in sequence, or to the wordm group, if the number of words in the search text is small, the memory consumption is greatly increased on the basis of the implementation class. If the number of words is too large and the initial 10000000, the system will crash. Therefore, we recommend that you use the searched words for dynamic memory allocation. You can use the memory to store words as needed. This balances the memory usage and avoids subscript escape.
2. in terms of sorting output of a word table, the Code sorts and outputs each word in a Word Table Based on the mode Value (0, 1, 2, in fact, 1 word, 2 word, and 3 word are stored in the word string in wordm. For word comparison and sorting output, the three methods are almost the same. dividing them into three writes will result in code redundancy. Therefore, after loading a Word Table Based on the mode type, we recommend that you write the sorting and output of the Word Table into one method respectively to make the code more clean and more concentrated.
3. the Code uses the method of determining the separator and then forming a word to store in the search for words that meet the requirements. We recommend that you use regular expressions to find the correct words, by changing the matching string of the regular expression, you can use the same search function to find the words that meet the requirements, in this way, the three functions for searching words can also combine a method to change the matching string for searching words through mode, which is more intuitive and reduces the code length to make the code clearer. You can also use the C # integrated map or dictionary type for word search to reduce the workload.
The advantage of the Code is that tasks are assigned to modules to complete tasks. The number of tasks in each module is close, so there is no need to focus on the problem. modules are closely linked and logical thinking is clear and strict, at the same time, exceptions are considered and handled to ensure the correctness and scientificity of code implementation. The definition of variables and methods is also scientific, easy to read and debug, and complies with code specifications.
Code peer review