Hello everyone;
I have a small question. I have an array like this :A=[7 8 5 9 10 5 11 12 5 10 11 12] . I need to find the index of 5 values in A and get the latest one; which means the index of 5 are B=[2 5 8] and change the latest one which is 8 to 100. I stacked the index values by using push_back()and generated B vector but it is so costly. How can I achieve this task more efficiently ? Thank you so much
Thank you @lastchance. I guess I did not understand well. You mean, without creating vector B, when I finish to read the indexes of A until the end of the vector, will I do a search backward?
@learner999, I may or may not have misunderstood what you wanted. A doesn't have anything with index 100, so why would you want to create a separate vector B containing two indices and a non-entity?
To avoid an XY problem, please make your ultimate intention clearer (give the WHOLE assignment).
Thank you so much @lastchance and @seeplus. I totally understood what you did and you got what I want to do. It will be better for me the version without generating another vector B.
Thank you so much for both of the answers..
Eh??? I don't understand. Can you explain again in more detail exactly what is your data and you are trying to accomplish. Provide a simple example of your input and expected output - noting that in the OP the syntax used is not that of c/c++.