Sort an Array of related Objects so that parents always precede their children