Say I have a demensional array, in the first row i have words, in the second one numbers, how can i sort the numbers from least to greatest?
Printable View
Say I have a demensional array, in the first row i have words, in the second one numbers, how can i sort the numbers from least to greatest?
You could make a binary heap, very fast result..Quote:
Originally posted by Azkar
Say I have a demensional array, in the first row i have words, in the second one numbers, how can i sort the numbers from least to greatest?
eh? binary heap? is there a MSDN i read up on it?
No a Binary Heap isn't a feature, it's a algorithm, it's simular to a bubble sort algorithm. Very easy to implement , I had to make one in a A* pathfinding algorithm I made.. just check here or you can check my code at PSC here and check out the portion of the code that uses a binary heap.Quote:
Originally posted by Azkar
eh? binary heap? is there a MSDN i read up on it?
Does the Array.Sort method support it?
How about system.array.sort("arrayname")?
System.Array.Sort(arSample) doesn't work: Only single dimension arrays are supported here.
Ohhhh those damn multi-dimensional arrays!!!!
But i tell you want. Here's some code for a BubbleSort. You just need to change it to work with multiple dimensions. It shouldn't take you more than a few minutes.
Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim arSample(4) As String
arSample(0) = "Jump"
arSample(1) = "Free"
arSample(2) = "Alpha"
arSample(3) = "Zebra"
arSample = BubbleSort(arSample)
For iLpr As Integer = 0 To UBound(arSample) - 1
ListBox1.Items.Add(arSample(iLpr))
Next iLpr
Beep()
End Sub
Public Function BubbleSort(ByVal arSort As Array) As Array
'Programmed by MrGTI on 1999.10.13 and revised 2003.11.03
'Gets upper bound of the sorting array (lower is always 0 in .NET)
Dim iArrayTop As Integer = UBound(arSort)
'Sorts array into alphabetical order
For iOuterLoop As Integer = 0 To iArrayTop - 1 'Number of passes = # in array minus 1
For iInnerLoop As Integer = 0 To iArrayTop - iOuterLoop
'This IF block allows the use of 0 in lBottom
If iOuterLoop = 0 And iInnerLoop = iArrayTop Then
'This is a single time when you don't want to check iInnerLoop + 1 (subscript out of range)
Else
'The AND statement stops the addition of a blank record
If arSort(iInnerLoop) > arSort(iInnerLoop + 1) And arSort(iInnerLoop + 1) > "" Then
Dim sTemp As String = arSort(iInnerLoop)
arSort(iInnerLoop) = arSort(iInnerLoop + 1)
arSort(iInnerLoop + 1) = sTemp
End If
End If
Next iInnerLoop
Next iOuterLoop
Return arSort
End Function
This function has a Syntax error and I'm not exactly sure what it is.....any ideas anyone???