Modify Remove_Element solution in cpp