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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting Array

Status
Not open for further replies.

Rish

Programmer
Jul 14, 2001
12
US
I need to sort an array of strings BUT need to keep a record of the original position of the string from the original array. ALSO store its position in another array (of integers).

e.g.

original array
of strings
0 B
1 B
2 A
3 C
4 F
5 G
6 D

sorted array new array
0 A 0 2
1 B 1 0
2 B 2 1
3 C 3 3
4 D 4 6
5 F 5 4
6 G 6 5

So the result is the original array (but sorted) and another array that contains the position of the original strings in the original unsorted array.

Can anyone help?
Thanks.
 

Const NumOfElm=7
Dim OriginalArray(NumOfElm-1) as String
Dim SortedArray(NumOfElm-1) As String
Dim NewArray(NumOfElm-1) as Integer
Dim IsMin(NumOfElm-1) As Boolean
Dim strMin as String
For i=0 to Ubound(OriginalArray)
IsMin(i)=False
Next
strMin=String(128,"z")
For i=0 to NumOfElm-1
For j=0 to NumOfElm-1
If Not Ismin(j) then
if strMin > OriginalArray(j) then
Pos=j : strMin=OriginalArray(j)
End If
End If
Next
SortedArray(i)=strMin
NewArray(i)=Pos
IsMin(i)=True
Next
 
Sorry, change the order
For i=0 to NumOfElm-1
strMin=String(128,"z")
For J=0 to NumOfElm-1
....
....
Next
....
Next
 
Hi,

I think there is an error here...

the line...

IsMin(i)=True

Should be...

IsMin(pos)=True

I think.

Rob Donovan.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top