Is there a function to sort variables in large or small order?

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)

6 Likes

another option would be to use the pre-defined qsort() from ANSI C

image

MySort.zip (1.8 KB)
program.zip (1.4 KB)

6 Likes

Thank you. I’ll try it

It’s nice to have various examples
Thank you.