An iterative algorithm to solve the generalized Sylvester tensor equations