code for sorting alg