Please see the answers on this question page:
Order of objects are changed for different runs of program?[
^].
On that page, Stefan Lang was the one to suggest a way of defining the order per your requirements and I argued against using the set. If you use the set and at the same time care of the order of elements, it's a clear indication that you should use some other container. In a set, sorting/ordering is just the implementation detail used to improve performance. The fundamental mathematical notion of the set does not assume having any order, but in implementation ordering is unavoidable, as soon as you have a way to traverse the set of elements.
And let me express my doubt about "I cannot change it". The "requirements" can be the matter of mistake exactly as any other programming mistake. This is the most important skill of the software developer to turn down any requirements with mistake and reconcile the problems with people developing requirements. After all, don't forget that if the requirement mistake originate from someone else, you will be responsible for the final result. And that is fair enough: this is because you did not speak up. Don't do this mistake.
—SA