#Sorting algorithm

10 messages · Page 1 of 1 (latest)

hoary crypt
#

I want to make a sorting algorithm that sorts one array of doubles from least to greatest. I want to make it so that another array is rearranged exactly the same way as the first array.

Example:

Array1 = {3, 4, 2, 1}
Array2 = {5, 6, 7, 8}

Sort

Array1 = {1, 2, 3, 4}
Array2 = {8, 7, 5, 6}

How would I go about doing this? What’s the fastest sorting algorithm for doing something like this? The arrays will be long, as in length > 1000. They will both be of the same length.

autumn bronzeBOT
#

This post has been reserved for your question.

Hey @hoary crypt! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

autumn bronzeBOT
hoary crypt
#

It’s pseuodocode

solid oak
#

you could make an int stream from 0..n, n being the length of both arrays, then sort that stream with a custom comparator getting the value of the first array, then use that sorted stream of indices to make a new array with the “sorted” second array

#

eg with
3, 1, 2
5, 6, 7

the stream would be 0, 1, 2 and be sorted to 1, 2, 0, which would then map to 6, 7, 5

hoary crypt
#

I’ll try that. Thank you

autumn bronzeBOT
# hoary crypt I’ll try that. Thank you

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

autumn bronzeBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.