陣列與矩陣 轉圈列印矩陣(C 版)

2021-09-18 07:36:39 字數 1257 閱讀 2422

//★題目:轉圈列印矩陣

//要求:給定乙個整型矩陣matrix,請按照轉圈的方式列印它。要求額外空間複雜度為o(1)。

// 例如: 1 2 3 4

// 5 6 7 8

// 9 10 11 12

// 13 14 15 16

// 列印結果為:1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10

//分析:逐邊列印外邊緣,外邊緣向內收

//注:此版本為自己寫的,左神版隨後有時間補上

#include #include using namespace std;

vectorresultprint;

void spiralorderprint(vector> matrix);

void printedge(vector> matrix, int left, int right, int top, int bottom);

void printvector2(vector> matrix);//列印二維矩陣

vector> generatestandard2vector(int setcols, int setrows);//生成二維矩陣

int main()

void spiralorderprint(vector> matrix)

cout << endl;

}void printedge(vector> matrix, int left, int right, int top, int bottom)

for (int i = top; i < bottom; i++)

for (int i = right; i > left; i--)

for (int i = bottom; i > top; i--) }

void printvector2(vector> matrix)

cout << endl; }}

vector> generatestandard2vector(int setcols,int setrows)

static int rows = 0;

while (rows < setrows)

result.push_back(tmp);

rows++;

} return result;

}

轉圈列印矩陣

題目 給定乙個整型矩陣matrix,請按照轉圈的方式列印它。例如 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 列印結果為 1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10 要求 額外空間複雜度為o 1 難度 1星 coding utf 8...

轉圈列印矩陣

輸入乙個矩陣,按照從外向裡以順時針的順序一次列印出每乙個數字。例如 輸入如下矩陣 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 輸出結果 1,2 3 4 8 12 16 15 14 13 9 5 6 7 11 10這個題的解法很簡單,就是矩陣分圈處理,每次都要列印最外...

轉圈列印矩陣

題目 給定乙個整形矩陣matrix,請按照轉圈的方式列印它。例如 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 列印結果為 1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10 要求 額外空間複雜度為o 1 分析 如果把思路限制在區域性座標怎麼...