Sort dependencies.