Sorts items according to a list of dependencies