据说可以用链表???我自己做了个QQ游戏的扑克记牌器,分析剩下没出的牌我觉得用数组很难删除元素,所以用了个Directinary词典,把0-53个元素排好,把出现的牌Remove掉,词典的数据就自动少了,而且还是按照从小到大排列,虽然好,但是觉得没学会算法,不怎么样记录其它两人出牌的数据的累计,把出牌后的数据进行排序,用数组我也不会,这方面我就用了集合Colection,但是用了集合我也只能按照他出牌的顺序进行累计记录,不知道怎么排序~~~~
请教各位,用什么方法好???虽然考虑过链表,但网上找来了很多代码,大都是有点缺陷的代码,不怎么如何用
请教各位,用什么方法好???虽然考虑过链表,但网上找来了很多代码,大都是有点缺陷的代码,不怎么如何用
解决方案 »
- ReadIniFile有这个函数吗,怎么用和申明啊
- 菜鸟提问~~!送分~!
- rs232和电机问题
- 使用Winsock Control 出错:Socket is non-blocking and the specified operation will block.
- 如何将picture中的图片导入到word中?
- 告诉我一些参数的值
- 我想得到DATAGRID里的行数该怎么做?
- 谁知道哪里有加密 文件夹 的软件啊(注意,是 文件夹 而不是文件)?或者,你能写一个出来吗?
- 吴文智!! 看到了进来!!
- VB用什么控件做表格
- 请问在AUTOCAD VBA中有无timer控件?
- 一个机子两个显示器,可以把消息发送到指定显示器吗
type card
... as ...
...
end type
public cards(1 to 54) as card
type card
showed as boolean
owner as string
......
end type
public hongtao(1 to 13) as card,fangpian(1 to 13) as card,....
然后就可以用hongtao(3).showed=true等等,定义这样的数组大大简化排序问题,当然这只是一个思路,具体怎么实现还得按照你的意思进行构思和优化,反正就这么几张扑克牌,也不必太在乎算法问题。
对于很少数据的操作,比如才54张扑克,集合会慢很多吗?那是你不能检测到的差距,也许做1万次,才差0.1秒而已。我用集合模拟过 Directinary 对象,原因是不想发行时带多一个 script.Directinary 组件,没感觉慢多少。
x.add "xxx","a1" 'a1 即是key取的时候 x.item("a1") 就行了。
'*类模块名称:clsDictionary
'*类模块说明:词典类,用集合模拟
'*
'*备注:用以代替 Script.Dictionary 对象
'*
'*作者:阿勇
'*日期:2006-09-21 15:57:14
'***************************************************************Private Const ModalName = "clsDictionary"'*key的前导字符,防止添加数字串 key 后,取出时识别成 index
Private Const preKey As String = "_"
Private m_Dict As CollectionPublic Sub Add(ByVal Key As String, ByVal Item As Variant)
m_Dict.Add Item, preKey & Key
End SubPublic Function Exists(ByVal Key As String) As Boolean
Exists = Exist1(Key) Or Exist2(Key)
End FunctionPrivate Function Exist1(ByVal Key As String) As Boolean
On Error GoTo proc_err Dim xItm As Variant
Set xItm = m_Dict.Item(preKey & Key)
Exist1 = True
Exit Functionproc_err:End FunctionPrivate Function Exist2(ByVal Key As String) As Boolean
On Error GoTo proc_err Dim xItm As Variant
xItm = m_Dict.Item(preKey & Key)
Exist2 = True
Exit Functionproc_err:End FunctionPublic Sub Remove(ByVal Key As String)
m_Dict.Remove preKey & Key
End SubPublic Sub RemoveAll()
' Dim i As Long
' For i = m_Dict.Count To 1 Step -1
' m_Dict.Remove i
' Next
Set m_Dict = Nothing
Set m_Dict = New Collection
End SubPublic Property Get Count() As Long
Count = m_Dict.Count
End PropertyPublic Property Get Item(ByVal Key As String) As Variant
On Error GoTo proc_err Set Item = m_Dict.Item(preKey & Key)
Exit Property
proc_err:
Item = m_Dict.Item(preKey & Key)
End PropertyPublic Property Get Items() As Collection
Set Items = m_Dict
End PropertyPrivate Sub Class_Initialize()
Set m_Dict = New Collection
End SubPrivate Sub Class_Terminate()
Set m_Dict = Nothing
End Sub
将它存为 cls 文件,加入工程。然后将你原来声明为:
dim ... as [new] script.Dictionary 或
dim ... as [new] Dictionary中的 diceionary 替代为 clsdDictionary ,其它代码不必改就能去掉 script.dictionary 对象的引用了。
当然如果你用的 dictionary 其它方法该类没有提供会出错了,把没实现的方法实现即可以了。
**************************************************************************
集合也可以用KEY的。不过KEY要是一个非数字符串,否则它可能识别成 indexadd 方法的第二个参数就是 keyDim x As Collection
x.add "xxx","a1" 'a1 即是key取的时候 x.item("a1") 就行了。
*************************************************************************集合添加元素的方法我知道~~~~我是觉得集合删除元素不适合我做记牌器集合删除元素是 x.Remove (Index)而Dictionary删除元素是 x.Remove (Key)通过删除指定的索引Index,会导致集合原来的元素对应的索引会变化而Dictionary删除的是Key,不存在变化的问题