分层交换,延迟swap

class Transform {
   public:
    vector<vector<int> > transformImage(vector<vector<int> > mat, int n) {
        // write code here
        int i = n - 1;
        int k = 0;
        while (i >= 1) {
            change(mat, k++, i, n);
            i -= 2;
        }
        show(mat, n);
        return mat;
    }
    void show(vector<vector<int> > &mat, int n) {
        cout << "-----" << endl;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cout << mat[i][j] << " ";
            }
            cout << endl;
        }
    }
    void change(vector<vector<int> > &mat, int dep, int length, int n) {
        cout << "**********" << endl;

        for (int i = 0; i < length; i++) {
            swap(mat[n - 1 - dep - i][dep], mat[n - 1 - dep][n - 1 - dep - i]);
        }
        show(mat, n);
        for (int i = 0; i < length; i++) {
            swap(mat[n - 1 - dep][n - 1 - dep - i], mat[dep + i][n - 1 - dep]);
        }
        show(mat, n);
        for (int i = 0; i < length; i++) {
            swap(mat[dep + i][n - 1 - dep], mat[dep][dep + i]);
        }
        show(mat, n);
    }
};