Sorting imagej plot values

Hello, i’m using BAR collection to do grayscale value calculation using Find Peaks.
Is it possible and How can i sort the plot values depending on X1 and X2 values rather than using their Y values? Because i need to process a large amount of image and simplify the method for my research.

Plot value

Best Regards,
Kevin

Using Array.rankPositions(array) you get the order of the elements which, when used, would be sorted. So if your array contains 1,7,5,3,2 the Array.rankPositions(array) would return 0,4,3,2,1 as that is the ascending order of elements. This macro shows the working:

Array.show(Array.rankPositions(newArray(1,7,5,3,2)));

Once you have obtained the sort order, you can grab the elements from your table in the correct order. Or am I missing your point?