我想排序一個多維數組,但我不確定這是否是正確的方法去解決它。到目前爲止,我在多維數組中獲取5個數字,然後將它們移動到單維數組中,並使用數組排序。知道更好的方法嗎?或者有關於如何改進我的想法?此外,代碼目前不在排序區域工作,它給了我一個索引超出陣列錯誤。排序多維數組
任何幫助將不勝感激。在此先感謝
Module q
Sub Main()
Randomize()
Dim Player,RandomNumber,NumberOfPlayers,Index As Integer
Dim Roll as Integer = 0
Console.Write("How many people will be playing Yahtzed?: ")
Player = convert.toint32(Console.Readline)
NumberOfPlayers = Player
Dim Game(Player,5) As Integer
Do until Player = 0
Console.Write("User")
Roll = 0
Do until Roll = 5
RandomNumber = CINT(Int((6 * Rnd()) + 1))
Game(Player,Roll) = RandomNumber
Roll += 1
Console.Write(" "&RandomNumber)
Loop
Player -= 1
Console.Writeline()
Loop
Player = NumberOfPlayers
Do until Player = 0
Dim Ordering(5) as Integer
Roll = 0
Do until Roll = 5
Ordering(Index) = Game(Player,Roll)
Roll += 1
Index += 1
Array.Sort(Ordering)
Loop
Loop
End Sub
End Module
我懷疑你想要一個數組而不是一個2維數組的數組。或者,更好的是,一個數組列表。是不是每個球員都有一個骰子擲骰的列表? –