我試圖在多維陣列中找到最低密度。
說一個陣列看起來像這樣
1 1 1
1 1 <- Lowest density is this one row:1 column:2.
1 1 1
1 1
1 1 1
1 <- Lowest density is this one row 2: column:1.
這是我損壞的代碼
Public ProcessedBits()() As Byte
'Lowest Density detector to find out which values have the highest priority.
Dim nextLowestDensityColumn As Integer = Integer.MaxValue
Dim nextLowestDensityRow As Integer = Integer.MaxValue
For Row = 0 To Uniques.Length - 1
For Column = 0 To Uniques(Row).Length - 1 'check each column in current row.
If ProcessedBits(Row)(Column) = 1 Then 'if the column is processed, then skip it and process the next one.
If Column < nextLowestDensityColumn AndAlso Row < nextLowestDensityRow Then
nextLowestDensityColumn = Column 1
nextLowestDensityRow = Row
End If
End If
Next
Next
If nextLowestDensityRow <> Integer.MaxValue AndAlso nextLowestDensityColumn <> Integer.MaxValue Then
Row = nextLowestDensityRow
End If
半固定碼
'Lowest Density detector to find out which values have the highest priority.
Dim nextLowestDensityColumn As Integer = Integer.MaxValue
Dim nextLowestDensityRow As Integer = Integer.MaxValue
For Row = 0 To Uniques.Length - 1
For Column = 0 To Uniques(Row).Length - 1 'check each column in current row.
If ProcessedBits(Row)(Column) = 1 AndAlso Uniques(Row).Length <> Column 1 AndAlso ProcessedBits(Row)(Column 1) = 0 Then 'if the column is processed, then skip it and process the next one.
If (Column 1) < nextLowestDensityColumn Then
nextLowestDensityColumn = Column 1
nextLowestDensityRow = Row
End If
End If
Next
Next
If nextLowestDensityRow <> Integer.MaxValue AndAlso nextLowestDensityColumn <> Integer.MaxValue Then
Row = nextLowestDensityRow
End If

uj5u.com熱心網友回復:
修復
'Lowest Density detector to find out which values have the highest priority.
Dim nextLowestDensityColumn As Integer = Integer.MaxValue
Dim nextLowestDensityRow As Integer = Integer.MaxValue
For Row = 0 To Uniques.Length - 1
For Column = 0 To Uniques(Row).Length - 1 'check each column in current row.
If ProcessedBits(Row)(Column) = 1 AndAlso Uniques(Row).Length <> Column 1 AndAlso ProcessedBits(Row)(Column 1) = 0 Then 'if the column is processed, then skip it and process the next one.
If (Column 1) < nextLowestDensityColumn Then
nextLowestDensityColumn = Column 1
nextLowestDensityRow = Row
End If
End If
Next
Next
If nextLowestDensityRow <> Integer.MaxValue AndAlso nextLowestDensityColumn <> Integer.MaxValue Then
Row = nextLowestDensityRow
End If
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/348905.html
上一篇:我需要使用byval傳遞一個串列,但是我知道我不能這樣做,因為串列仍然會被更改,但是創建一個“新”串列會減慢我的代碼
