Two algorithms for sorting a file in Cpp