A method to study the Krall and q -Krall polynomials