Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alphanumeric sorting

Status
Not open for further replies.

bjrollet

Programmer
Apr 10, 2002
118
0
0
US
Het all,

I have a one dimension array that conatains alphanumeric strings -
Code:
tmpArray(0)="1-0-1"
tmpArray(1)="10-0-0"
tmpArray(2)="7-0-1"
...

How can a sort them so they are in order?
Code:
tmpArray(0)="1-0-1"
tmpArray(1)="7-0-1"
tmpArray(2)="10-0-0"


Any good sorting algorithims out there? This working out thing isn't working out.
 
Ever hear of a bubble sort? It is a very simple sorting alogrithm generally considered slow and ineffecient though it's inadequacies don't appear until somewhere around 5000 items. Search for bubble sort on Google.ca you'll find lots.

Or you can check this site out seems to be a good starting point.
That'l do donkey, that'l do
[bravo] Mark
 
The Array Class has a Sort method but it will not sort a string based on an internal "number", just straight Ascii.

Zarcom.
Why "Bubble Sort" when the Array Class has a Sort method? Also a 5000 item bubble sort requires at least 12.5 million compares (N^2+N)/2. Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
You just asked for an algorithm so I mentioned a simple one. I wasn't sure what you were after. And still I am not. The link I provided has a lot of good algorithms if you look through it. That'l do donkey, that'l do
[bravo] Mark
 
Dim arySplit() as String
Dim arySort() As String
Redim arySort(Ubound(tmpArray))
' Create new array
' tmpArray = "1-0-1", "10-0-0", "7-0-1" To
' to "001-000-001", "010-000-000", "007-000-001"
For I = 0 To Ubound(tmparray)
arySplit = Split(tmparray,"-") ' get numbers
For J = 0 To Ubound(arySplit)
arySplit(J) = arySplit(J).PadLeft(4,"0") ' Right Justify
Next
arySort(I) = Join(arySplit,"-") ' put back together
Next
'Sorts a pair of one-dimensional Array objects (one
' contains the keys and the other contains the corresponding
' items) based on the keys in the first Array using the
' IComparable interface implemented by each key.
System.Array.Sort(arySort, tmparray) ' Sort 1st, rearrange 2nd

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Sorry John I got all mixed up. I thought that you had asked the question.

Didn't know about the sort method though. Thanks for that. That'l do donkey, that'l do
[bravo] Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top