我正在尝试使用算法对数组进行排序,但我的索引出现问题。
Sub Main()
Dim List() As Integer = {9, 8, 5, 6}
Dim InnerPointer As Integer = 0
Dim CurrentValue As Integer
For OutPointer = 1 To List.Length - 1
CurrentValue = List(OutPointer)
While InnerPointer > 0 And List(InnerPointer) > CurrentValue
List(InnerPointer + 1) = List(InnerPointer)
InnerPointer = InnerPointer - 1
End While
List(InnerPointer + 1) = CurrentValue
Next
For Each element In List
Console.WriteLine(element)
Next
Console.ReadKey()
End Sub
我将InnerPointer定义为0,因为我的数组基于0索引,但这意味着我的While循环不会启动...但我确实想要将索引0与索引1进行比较以确定哪个数字更大。我不能为我的生活找出逻辑谬误所在的地方