lazytrucker
Programmer
Almost got this sussed but cant get over the last hurdle, trying to sort both dimensions of the array at once.
Unsorted Output:
Number:= 1 Cost:= 375.20
Number:= 2 Cost:= 375.20
Number:= 3 Cost:= 537.30
Number:= 4 Cost:= 537.30
Number:= 5 Cost:= 45.00
Number:= 6 Cost:= 45.00
Number:= 7 Cost:= 45.00
Number:= 8 Cost:= 45.00
Code:
For i=1 to l
For j=i+1 to l
if arr(1,i)>arr(1,j) then
TemporalVariable=arr(1,i)
arr(1,i)=arr(1,j)
arr(0,i)=j
arr(1,j)=TemporalVariable
end if
next
next
Sorted Output:
Number:= 5 Cost:= 45.00
Number:= 6 Cost:= 45.00
Number:= 7 Cost:= 45.00
Number:= 8 Cost:= 45.00
Number:= 7 Cost:= 375.20
Number:= 8 Cost:= 375.20
Number:= 7 Cost:= 537.30
Number:= 8 Cost:= 537.30
As you can see the output has sorted the cost but not the numbers, which have to relate to the correct price.
If this line is taken out the loop arr(0,i)=j then the numbers simply run from 1 to 8.
Is there a way of getting the two dimensions to always relate to each other?
Or can anyone think of some extra conditioning in order to match up the two dimensions?
Cheers LazyTrucker.
Unsorted Output:
Number:= 1 Cost:= 375.20
Number:= 2 Cost:= 375.20
Number:= 3 Cost:= 537.30
Number:= 4 Cost:= 537.30
Number:= 5 Cost:= 45.00
Number:= 6 Cost:= 45.00
Number:= 7 Cost:= 45.00
Number:= 8 Cost:= 45.00
Code:
For i=1 to l
For j=i+1 to l
if arr(1,i)>arr(1,j) then
TemporalVariable=arr(1,i)
arr(1,i)=arr(1,j)
arr(0,i)=j
arr(1,j)=TemporalVariable
end if
next
next
Sorted Output:
Number:= 5 Cost:= 45.00
Number:= 6 Cost:= 45.00
Number:= 7 Cost:= 45.00
Number:= 8 Cost:= 45.00
Number:= 7 Cost:= 375.20
Number:= 8 Cost:= 375.20
Number:= 7 Cost:= 537.30
Number:= 8 Cost:= 537.30
As you can see the output has sorted the cost but not the numbers, which have to relate to the correct price.
If this line is taken out the loop arr(0,i)=j then the numbers simply run from 1 to 8.
Is there a way of getting the two dimensions to always relate to each other?
Or can anyone think of some extra conditioning in order to match up the two dimensions?
Cheers LazyTrucker.