public static List <string> BuildCode(List <string> dictionary) { var encodedDictionary = new List <string>(); int codeLength = (int)Math.Ceiling(Math.Log(dictionary.Count, 2)); for (int j = 0; j < dictionary.Count; j++) { var code = new BitArray(BitConverter.GetBytes(j)); String stringCode = StringManipulator.BitToString(code, codeLength); if (!encodedDictionary.Contains(stringCode)) { encodedDictionary.Add(stringCode); } } MessageBox.Show("Средняя длинна кодового слова: " + codeLength.ToString()); return(encodedDictionary); }
public List <string> Encode(List <string> dictionary) { var result = new List <string>(); for (int i = 0; i < dictionary.Count; i++) { List <bool> encodedSymbol = Root.Traverse(dictionary[i], new List <bool>()); result.Add(StringManipulator.BitToString(new BitArray(encodedSymbol.ToArray()))); b += result[i].ToString().Length *d[dictionary[i]]; c += d[dictionary[i]]; } MessageBox.Show("Средняя длинна кодового слова: " + b.ToString()); return(result); }