You could use a data structure which is automatically sorted. BSD tree.h provides some macros which do this for you, but they might be a bit tricky to use at first. For example, if you define a list...