public void Load(string key, string name) { Keys.Add(key); var ch = name[0]; var node = Nodes.FirstOrDefault(q => q.Char == ch); if (node == null) { node = new NameTree(); node.Char = ch; //node.IsNum = "0123456789".Contains(ch); node.Name = this.Name + ch; this.Nodes.Add(node); } if (name.Length == 1) { node.CurKeys.Add(key); } else { var next = name.Substring(1); node.NextKeys.Add(key); node.Load(key, next); } }
private List <string> getMinName(Dictionary <string, string> dict, List <string> names) { NameTree root = new NameTree(); foreach (var item in dict) { root.Load(item.Key, item.Value); } root.OrderBy(); //var names2 = names.OrderBy(q => q).ToList(); List <string> list = new List <string>(); foreach (var item in names) { var name = root.GetName(item); if (list.Contains(name) == false) { list.Add(name); continue; } name = getSimpleName(item); if (list.Contains(name) == false) { list.Add(name); continue; } for (int i = 2; i < 10; i++) { var n = name + i; if (list.Contains(n) == false) { list.Add(n); break; } } } return(list); //List<string> list2 = new List<string>(); //foreach (var item in names) { // var t = names2.IndexOf(item); // list2.Add(list[t]); //} //return list2; }