Is there a function to sort variables in large or small order?
I’m making an elevator for practice
I want to align the floors where the direction of the elevator and the direction of the upper and lower buttons of the building match, but I don’t know how
Hi,
I’m not sure if I got your usecase completely right, but if you want to sort data in a array, maybe the bubble sort algorithm fits to your needs.
Bubble Sort is not the most efficient sorting algorithm because of using nested loops, but how it works is easy to understand and if you don’t have a hughe amount of data to sort it can be used.
I made a short example for bubble sort in ST with 10 unsorted values, please see attached Automation Studio task.
Before sorting:
After sorting:
BubbleSort.zip (1.6 KB)
another option would be to use the pre-defined qsort() from ANSI C
MySort.zip (1.8 KB)
program.zip (1.4 KB)
Thank you. I’ll try it
It’s nice to have various examples
Thank you.
The replies above from @alexander.hefner and @christoph.hilchenbac both provide solutions to the question at hand.