|
-
Aug 15th, 2003, 03:23 PM
#1
Thread Starter
Lively Member
Sorting items in an array.
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?
-
Aug 15th, 2003, 04:10 PM
#2
Hyperactive Member
Re: Sorting items in an array.
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?
You could make a binary heap, very fast result..
-
Aug 15th, 2003, 09:51 PM
#3
Thread Starter
Lively Member
eh? binary heap? is there a MSDN i read up on it?
-
Aug 16th, 2003, 01:48 AM
#4
Hyperactive Member
Originally posted by Azkar
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.
-
Aug 16th, 2003, 11:53 AM
#5
PowerPoster
Does the Array.Sort method support it?
-
Nov 3rd, 2003, 01:54 AM
#6
New Member
How about system.array.sort("arrayname")?
-
Nov 3rd, 2003, 12:44 PM
#7
Frenzied Member
System.Array.Sort(arSample) doesn't work: Only single dimension arrays are supported here.
~Peter

-
Nov 3rd, 2003, 12:56 PM
#8
New Member
Ohhhh those damn multi-dimensional arrays!!!!
-
Nov 3rd, 2003, 01:12 PM
#9
Frenzied Member
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
~Peter

-
Dec 9th, 2003, 02:10 PM
#10
Fanatic Member
This function has a Syntax error and I'm not exactly sure what it is.....any ideas anyone???
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|