Indexing into Vectors of structures:
Frequently, when the data structure is a vector of structures, it is essential to iterate through the vector in order by various fields. For illustration, for the packages vector defined formerly, it may be essential to iterate in order by the cost, or by the price fields. Instead of sorting the whole vector of structures depends on these fields, it may be more proficient to index into the vector depend on these fields, for illustration, to have an index vector based on cost and the other based on price.
Such index vectors would be generated as before, comparing the fields but exchanging the values in the index vectors. The index vectors have been once created, then they can be used to iterate through the packages vector in the preferred order