On Friday, 1 October 2021 at 17:53:24 UTC, Steven Schveighoffer wrote:
I think your struct is different than this, because this only happens if aliasing is inside the struct being sorted (i.e. it has pointers). Your presented struct doesn't have pointers, and the code you linked to is completely parameterized on the struct type.

If it does have pointers, you are not allowed to swap the values if either points to each other (or themselves).

Thanks Steve for saving Friday,

The struct has indeed a parent pointer, It's a pretty big struct so just posted the excerpt (sorry). So that's the cause then.

So how to sort this N[] object by f() then ?

The pointer is only used to be traversed back after the search has finished. Is there a sort() algorithm that avoids swapping the items themselves and e.g. just returns the indexes so I can reorder the original array myself ?

Danny

Reply via email to