How can I sort elements in single-linked list (by some value like list->id)? The idea I’ve came up with is to find maximal value and save its index. Then iterate through the list so that the *head pointer points to that element…And then swap this element with the first one. The last sentence… how can I do that?
Share
It’s often easier to just swap the data, rather than “re-linking” the list so the order of the actual list nodes is altered.
If your field is an integer, you could do something like: