Using python to implement tree select sort algorithm