You cannot 'sort any object'.
Strictly speaking you may just sort sets
having an order criterion defined
If you need sorting a collection (e.g. an array) of objects then the latter must provide a property (say 'key'
) such that using it you are be able establish the relative order of any
two of them.
Supposing the objects provide such a key
then you may use a well-known-good algorithm (like for instance Quick Sort
] ) for sorting them.