algorithm - How to rearrange an array by another array of indexes in c++ -


given array:

int data[5] = {data[0],data[1],data[2],data[3],data[4]} 

…and array indexes:

int idx[5] = {3,1,0,2,4} 

what fastest way rearrange data[5] array, resulting (sorted) array becomes:

data[5] = {data[3],data[1],data[0],data[2],data[4]} 

sort array in pairs based on indexes: comparison , reordering operation in reference array, move corresponding indexes in other array such well.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -