logo CodeStepByStep logo

rotate

Language/Type: C++ Grid collections
Related Links:
Author: Danielle Kain (on 2016/10/04)

Write a function named rotate that accepts accepts a reference to a grid of integers as a parameter and rotates the grid 90 degrees clockwise. You may assume the grid has the same number of rows as columns. For example, if a variable named g stored the grid below at left, the call of rotate(g); would alter it to give it the new grid state at right:

{{ 6,  1,  9,  4},             {{21, 14, -2,  6},
 {-2,  5,  8, 12},              {55, 39,  5,  1},
 {14, 39, -6, 18},     -->      {73, -6,  8,  9},
 {21, 55, 73, -3}}              {-3, 18, 12,  4}}
Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.