' 背包的作用,只负责搜集,在搜集完成后循环遍历背包内的对象,没有多余的用途Private head As Node
Private n AsLongSub add(i As Variant)Dim newNode AsNew Node
newNode.letItem = i
newNode.letNext = head
Set head = newNode
n = n +1EndSubPublicFunctionsize()AsLongsize= n
EndFunctionPublicFunction isEmpty()AsBoolean
isEmpty = head IsNothingEndFunctionPublicFunction hasNext()AsBoolean
hasNext =Not head IsNothingEndFunctionPublicFunction doNext()As Variant
If isEmpty()Then Err.Raise 404,"Bag.doNext", "背包已经空了,没有下一个。"
assign doNext, head.getItem
Set head = head.getNext
n = n -1EndFunctionPrivateSub assign(ByRef x,ByVal y)If IsObject(y)ThenSet x = y
Else
x = y
EndIfEndSub