嗨,有一个 C 代码,其中我有一个 2D 字符数组 -
names[100][20] //Currently maximum 100 names, each of 19 characters supported
这个数组被一些带有名字的逻辑填充。我在变量 names_found 中跟踪实际找到的名称总数(可能少于 100 个名称)。
现在我想删除可能存在的重复名称。我打算做的是类似的事情。
for(i=0;i<names_found;i++)
{
for(j=i+1;j<names_found;j++)
{
//Then compare(strcmp) each string/name with every other.
//e.g. if there were 4 names the comparisons done would be
//{name[0],name[1]},{name[0],name[2]},{name[0],name[3]}
//{name[1],name[2]} , {name[1],name[3]}
//& {name[2],name[3]}
//And then some more logic to remove duplicate based on result of strcmp results. Don't know what this logic would look like to store the result in place, in same 2D character buffer?
}
这
是重复词删除的逻辑,我在做什么正确,功能上?
我怎样才能优化它的速度。
任何更好/更快的解决方案。