Rotate algorithm using reverse in chapter 2.