This is an age old question, caused mostly by the unstructured format of the version numbers.
The simple answer is to make each of the "units" in the version number zero filled to some arbitrary width, so that your numbers would become 01.05.05.09 or something like that. This makes the numbers sortable as strings.
Another solution would be to change the storage from character to some form of binary. This would allow the version numbers to be sorted arbitrarily.
You have to figure out what solution works best for your problem.
-PatP