Recursive rotate algorithm in chapter 2.