I made a planetarium that plots the celestial bodies on a 3.5" LCD. In the calculation I determine the distance for each celestial body. These go in an array. Each element has 2 values, the index of the celestial body and the distance. I want to sort this array by distance see the layout how can this be realized with the arduino (esp32).
//before sort:
distance = {{1,13.4},{2,4.3},{3,0.026},{4,5.66}};
after sort:
//distance = {{1,13.4},{4,5.66},{2,4.3},{3,0.026}};
As a learning exercise, that is instead of using a ready made library, the Exchange Bubble Sort would be a good choice. It is space efficient because it works in the original array. However, it can be slow.
In principle, you scan the array linearly. If the next item to be read has a value higher that the current item just read, swap them. Move on to the next until the end. Your sort is complete when you do a full scan without swapping any items.
Edit
Thanks to @ua6em. Bubble sort. Not Exchange sort
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for advice on (nor for problems with) your project.