Quicksorts items based on densities