Connect back to ... 3 {if (last_code == - 1) {// first code string corresponding to the output of the code Char Stream;} else {if (this_code present in the string_table) {current_string = string (last_code); current_string = string (this_code) [0]; // t_code The first character of String plums current_string into the end of String_Table; This_code output corresponding to a string Char Stream;} else {current_string = string (last_code); current_string = string (last_code) [0]; string // last_code first character corresponding to the string_table current_string inserted at the end; Output current_string to Char Stream;
}}}} Last_code = this_code;} This algorithm has several places that are not well understood. When Last_code is equal to -1, our approach is to simply output the string corresponding to Code, this has a question: this code Does the corresponding String must exist? Let us think about the process of coding, the first code must be root INDEX, so this string is existing. The second question is to process this_code. We know that when you initialize String Table, it only has root_number items, with the coded process, this table grows, but still may have a Code but found that it is still generated in the string Table species. Case. In combination with the encoding process, it should not be difficult to understand. If there is no existence, then this code should be just a big one more than the biggest index in the current table, that is, if we can use some way to get this item, you should join. Then it is what we have to find. The third question is why we always insert a String into string_table after reading a code, and is still a reference encoding process. We always generate a string to insert to Table while outputting a code. That is to say, when we decode, if you want string_table to synchronize when you encode us, you have to generate a string into the Table after reading a code. The last question is the solution for "Code does not exist in string_table". As you can see from the pseudo code, if the Code exists, construct current_string and output are well understood, but if there is no existence, it seems that it is very shameless to use Last_Code Lee's current_string, in fact, carefully contact the encoding method to understand: this way It is inevitable. Still look at an example: It is still an example of just, and we will take the code we have elected.