对于遇到的每个循环'集合已修改;枚举操作可能无法执行,但我需要在运行时更改列表的大小
我正在尝试使用 .NET 6 在 VB 中编写霍夫曼编码系统。这是当前的主要代码,使用“ConstructionQueue”作为优先级队列来处理添加到“Tree”列表中的节点。 'Node' 是一个抽象类,'LeafNode' 和 'InternalNode' 继承自该抽象类;当这个类运行时,ConstructionQueue 仅填充了 LeafNode。我的问题是,我需要在初始化过程中将 InternalNode 添加到队列中进行处理。这是当前的代码:
Public Class HuffmanTree
Private Tree As New List(Of Node)
Public Sub New(ByVal ConstructionQueue As PriorityQueue)
Dim PairMade As Boolean = False
Dim NodesProcessed As Integer = 0
Dim TempWeight As Integer
For Each Node In ConstructionQueue.QueueFrame
If ConstructionQueue.GetFrontPointer <> 0 And ConstructionQueue.GetFrontPointer Mod 2 = 0 Then
PairMade = True
End If
Tree.Insert(NodesProcessed, Node)
If PairMade = True Then
Dim TempNode As New InternalNode(ConstructionQueue.QueueFrame(ConstructionQueue.GetFrontPointer).GetWeight + TempWeight)
TempNode.SetLeftPointer(Tree(NodesProcessed - 1))
TempNode.SetRightPointer(Tree(NodesProcessed))
ConstructionQueue.Enqueue(TempNode)
PairMade = False
Else
TempWeight = Node.GetWeight
End If
NodesProcessed += 1
ConstructionQueue.SetFrontPointer(NodesProcessed)
Next
End Sub
End Class
集合已修改;枚举操作可能无法执行。
是我在 End Sub 之前的“Next”中收到的错误。我完全理解为什么,问题是我无法更改“QueueFrame”列表的大小,但我需要一种方法来执行此操作,该方法允许我遍历列表中的每个节点,同时能够更改它的大小,因为在使用它时,我需要将多个实例添加到列表中。
有谁知道有任何解决方法或修复此问题吗?我很乐意提供所需的更多信息。
I'm attempting to code a Huffman Encoding system in VB, using .NET 6. Here is the main code as it currently stands, using 'ConstructionQueue' as a priority queue to handle the nodes being added to the 'Tree' list. 'Node' is an abstract class from which 'LeafNode' and 'InternalNode' inherit; at the time this class is run, ConstructionQueue is filled with only LeafNode's. My issue is that I need to add InternalNodes to the queue during this initialization process to be handled. Here is the current code:
Public Class HuffmanTree
Private Tree As New List(Of Node)
Public Sub New(ByVal ConstructionQueue As PriorityQueue)
Dim PairMade As Boolean = False
Dim NodesProcessed As Integer = 0
Dim TempWeight As Integer
For Each Node In ConstructionQueue.QueueFrame
If ConstructionQueue.GetFrontPointer <> 0 And ConstructionQueue.GetFrontPointer Mod 2 = 0 Then
PairMade = True
End If
Tree.Insert(NodesProcessed, Node)
If PairMade = True Then
Dim TempNode As New InternalNode(ConstructionQueue.QueueFrame(ConstructionQueue.GetFrontPointer).GetWeight + TempWeight)
TempNode.SetLeftPointer(Tree(NodesProcessed - 1))
TempNode.SetRightPointer(Tree(NodesProcessed))
ConstructionQueue.Enqueue(TempNode)
PairMade = False
Else
TempWeight = Node.GetWeight
End If
NodesProcessed += 1
ConstructionQueue.SetFrontPointer(NodesProcessed)
Next
End Sub
End Class
Collection was modified; enumeration operation may not execute.
is the error I receive on the 'Next' before End Sub. I completely understand why, the issue is that I can't alter the size of the 'QueueFrame' List, but I need a method of doing this that is going to allow me to go through each node in the list whilst being able to change its size, as there will be multiple instances where I need to add to the list as I'm using it.
Does anyone know of any sort of workaround or fix to this? I'd be happy to provide any more information needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论