Given a list of objects, which point to other objects write a function that would sort them in such a way that objects that are referenced by others come after them