Stability for a class of difference equations