Points of my curve are not in order, what happend here?

Have you tried any algorithm, e.g. traveling salesman algorithm? There is a node from Sparrow package, for Revit 2021. See here