RyanBank
asked on
array sort
Hi,
Two arrays called:
Dim Arr_ReqConverted() As String <--this contains the actual values
Dim Arr_First7Highest(6) As Integer <---this is a index value pointer to Arr_ReqConverted()
how can we re-arrange and sort the arr_first7highest(6) ? re-arrangeing arr_first7highest(6) -highest to lowest
Note:We need to lookup the real value in Arr_ReqConverted() to determine the sort order.
i.e.
Arr_ReqConverted() = 102,201,30,405,50,60,70,80 ,90,100
Arr_First7Highest(6)=2,4,6 ,1,9,5,7
lookup element actual valueArr_ReqConverted(Arr_ First7High est(0))=30
lookup element actual valueArr_ReqConverted(Arr_ First7High est(1))=50
lookup element actual valueArr_ReqConverted(Arr_ First7High est(2))=70
lookup element actual valueArr_ReqConverted(Arr_ First7High est(3))=20 1
lookup element actual valueArr_ReqConverted(Arr_ First7High est(4))=10 0
lookup element actual valueArr_ReqConverted(Arr_ First7High est(5))=60
lookup element actual valueArr_ReqConverted(Arr_ First7High est(6)=80
desired output:
Arr_First7Highest(6)=1,9,7 ,6,5,4,2
currently stuck:
Dim Best_J As Integer
Dim J As Integer
Dim Best_ValueConverted As Integer
Dim Best_Value As Integer
For i = 0 To 6 - 1
Best_ValueConverted = Arr_ReqConverted(Arr_First 7Highest(i ))
Best_J = i
For J = i + 1 To 6
If Arr_ReqConverted(Arr_First 7Highest(J )) > Best_ValueConverted Then
Best_ValueConverted = Arr_ReqConverted(Arr_First 7Highest(J ))
Best_Value = Arr_First7Highest(J)
Best_J = J
End If
Next
Arr_First7Highest(Best_J) = Arr_First7Highest(i)
Arr_First7Highest(i) = Best_Value2
Next i
Two arrays called:
Dim Arr_ReqConverted() As String <--this contains the actual values
Dim Arr_First7Highest(6) As Integer <---this is a index value pointer to Arr_ReqConverted()
how can we re-arrange and sort the arr_first7highest(6) ? re-arrangeing arr_first7highest(6) -highest to lowest
Note:We need to lookup the real value in Arr_ReqConverted() to determine the sort order.
i.e.
Arr_ReqConverted() = 102,201,30,405,50,60,70,80
Arr_First7Highest(6)=2,4,6
lookup element actual valueArr_ReqConverted(Arr_
lookup element actual valueArr_ReqConverted(Arr_
lookup element actual valueArr_ReqConverted(Arr_
lookup element actual valueArr_ReqConverted(Arr_
lookup element actual valueArr_ReqConverted(Arr_
lookup element actual valueArr_ReqConverted(Arr_
lookup element actual valueArr_ReqConverted(Arr_
desired output:
Arr_First7Highest(6)=1,9,7
currently stuck:
Dim Best_J As Integer
Dim J As Integer
Dim Best_ValueConverted As Integer
Dim Best_Value As Integer
For i = 0 To 6 - 1
Best_ValueConverted = Arr_ReqConverted(Arr_First
Best_J = i
For J = i + 1 To 6
If Arr_ReqConverted(Arr_First
Best_ValueConverted = Arr_ReqConverted(Arr_First
Best_Value = Arr_First7Highest(J)
Best_J = J
End If
Next
Arr_First7Highest(Best_J) = Arr_First7Highest(i)
Arr_First7Highest(i) = Best_Value2
Next i
It is very difficult to understand ur question. Can u elabrate the above step by step. So, we can help u appropriately.
ASKER
we need to sort the values in Arr_First7Highest(6) but inorder to sort properly, we need to lookup the value in Arr_ReqConverted()
i.e.
Arr_ReqConverted() = 102,201,30,405,50,60,70,80 ,90,100
Arr_First7Highest(6)=2,4,6 ,1,9,5,7
lookup element actual valueArr_ReqConverted(Arr_ First7High est(0))=30
lookup element actual valueArr_ReqConverted(Arr_ First7High est(1))=50
lookup element actual valueArr_ReqConverted(Arr_ First7High est(2))=70
lookup element actual valueArr_ReqConverted(Arr_ First7High est(3))=20 1
lookup element actual valueArr_ReqConverted(Arr_ First7High est(4))=10 0
lookup element actual valueArr_ReqConverted(Arr_ First7High est(5))=60
lookup element actual valueArr_ReqConverted(Arr_ First7High est(6)=80
desired output:
Arr_First7Highest(6)=1,9,7 ,6,5,4,2
i.e.
Arr_ReqConverted() = 102,201,30,405,50,60,70,80
Arr_First7Highest(6)=2,4,6
lookup element actual valueArr_ReqConverted(Arr_
lookup element actual valueArr_ReqConverted(Arr_
lookup element actual valueArr_ReqConverted(Arr_
lookup element actual valueArr_ReqConverted(Arr_
lookup element actual valueArr_ReqConverted(Arr_
lookup element actual valueArr_ReqConverted(Arr_
lookup element actual valueArr_ReqConverted(Arr_
desired output:
Arr_First7Highest(6)=1,9,7
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
TimCottee,
Outstanding, works like a charm!
What sorting algorithm is this?
Thanks.
Outstanding, works like a charm!
What sorting algorithm is this?
Thanks.
RyanBank,
It is a kind of bubble-sort, essentially it switches position of elements that are higher or lower. So it may take more iterations of the loop if the elements are very unsorted to start with but fewer iterations if they are well sorted. Overall it is actually a quick way to sort elements especially with larger arrays.
Tim
It is a kind of bubble-sort, essentially it switches position of elements that are higher or lower. So it may take more iterations of the loop if the elements are very unsorted to start with but fewer iterations if they are well sorted. Overall it is actually a quick way to sort elements especially with larger arrays.
Tim
RyanBank,
What I should point out is that on each iteration it assumes to start with that no switches take place, if we have to switch then we set blnSorted to false so it goes through again. If no switches can take place it is all perfectly sorted and we can exit the loop.
Tim
What I should point out is that on each iteration it assumes to start with that no switches take place, if we have to switch then we set blnSorted to false so it goes through again. If no switches can take place it is all perfectly sorted and we can exit the loop.
Tim
ASKER
TimCottee,
is it okay if you can please kindly assist:
https://www.experts-exchange.com/questions/21813855/array-algorithm.html
is it okay if you can please kindly assist:
https://www.experts-exchange.com/questions/21813855/array-algorithm.html