Is there a simple way of sorting a vector based on 2 others without losing the original index of the elements in C++?
Given an array of elements, Ive got two arrays that contains data identifying each element. For example, element number k is identified by the value contained in position k of both of the arrays. These arrays contain int type values and they can represent the weight and value of each element or whatever.
Im programming a greedy algotithm that picks first the elements with better relation (a/b) in their values. This can be archieved by checking first the elements with the better relation between its respective values in the arrays and to archive that Ive thought that storing the elements in one array and sorting them by the relation might be the way to go because only thing I would need in my greedy algorithm is taking the first, then the second and so on untill there isnt any more left to pick or the limit is exceeded.
My question is if there is an easy way of doing this.