如何在数组中查找重复值 [英] how to find duplicate values in a array

查看:92
本文介绍了如何在数组中查找重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨所有

iam使用vb6.0可以任何人告诉我如何复制数组中的值如果可能我想删除重复值

紧急

谢谢

hi to all
iam using vb6.0 can any one tell me how to duplicate values in a array if possible i want to delete the duplicate values
its urgent
thanks

推荐答案


嗨所有

iam使用vb6.0可以任何人告诉我如何复制数组中的值如果可能我想删除重复值

紧急

谢谢
hi to all
iam using vb6.0 can any one tell me how to duplicate values in a array if possible i want to delete the duplicate values
its urgent
thanks



是的,有很多方法和方法,有些方法和方法比其他方法更快。最差,更慢,但更容易检查每一个与每一个,让我们说你的阵列是Arr1

yes, there are many ways and methods, some faster than others. The worst, slower, but easier will be to check each one vs each one, lets say your array is Arr1

展开 | 选择 | 换行 | 行号


我不认为你会找到更快的方法。很多人犯的错误就是每次从内部循环开始。


另请注意,只有当元素的顺序不重要时,您的自制函数才会起作用。哦,您可能会发现需要进行一些额外的测试或错误处理,因为您的代码可能会尝试超过阵列的末尾。


但是,怎么样?替代?如果您使用集合而不是数组,则可以轻松地防止首先添加任何重复项。


有一些小调整可能有所作为。我会按可能的性能影响的降序列出它们......
  • 确保自制功能。为了减少调用它所用的时间,它是在线编码而不是实际函数。
  • 跟踪上限并在最后做一个 ReDim Preserve ,而不是每次删除条目。
  • 将所有整数变量更改为
  • 定义 i j 整数。您当前将它们定义为默认类型,很可能是变体。 (不,检查你的语法 - 它们定义为整数。只有 n 是。)
  • 下一步<删除变量名称/ b>陈述。 (这来自BASIC的旧版本,可能与VB没有关系,但无论如何你也不需要它们。)
I don''t think you''ll find many faster methods. The mistake a lot of people make is starting the inner loop form the beginning each time.

Note also, your home-made function will work only if the sequence of the elements is not significant. Oh, and you may find that a bit of extra testing or error-handling is required, since your code may try to go past the end of the array.

However, what about an alternative? If you use a collection rather than an array, you can easily prevent any duplicates being added in the first place.

There are a couple of minor tweaks which might make some difference. I''ll list them in descending order of possible performance impact...
  • Make sure the "home-made function" is coded in-line rather than as an actual function, to reduce time used up in calling it.
  • Keep track of the upper bound and just do one ReDim Preserve at the end, rather than each time you remove an entry.
  • Change all Integer variables to Long.
  • Define i and j as Integer or Long. You currently have them defined as the default type, most likely Variant. (No, check your syntax - they are not defined as Integer. Only n is.)
  • Remove variable names from the Next statements. (This comes from an older version of BASIC and may not relate to VB, but you don''t need them anyway.)
  • 什么是 list()
  • 需要在开始时设置 n = 0 。它刚刚被创造出来。
  • 实际上,你甚至不需要定义 n ,因为它没有被使用。
  • What the heck is list()?
  • You do not need to set n = 0 at the start. It''s only just been created.
  • Actually, you don''t even need to define n, since it isn''t used.




如果使用数据库,最快的方法之一就是将所有数组值添加到TempTable中。并查询不同的字段值..


问候

Veena
Hi,

One of the Fastest way would be, if using a Database, add all the Values of Array to a TempTable. And Query Distinct Field Values..

Regards
Veena


这篇关于如何在数组中查找重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆