-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtranspose.c
More file actions
31 lines (23 loc) · 826 Bytes
/
transpose.c
File metadata and controls
31 lines (23 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <stdlib.h>
/**
* Return an array of arrays of size *returnSize.
* The sizes of the arrays are returned as *returnColumnSizes array.
* Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
*/
int** transpose(int** A, int ASize, int* AColSize, int* returnSize, int** returnColumnSizes) {
//开辟一个大小为 AColSize的数组
int** num=(int**)malloc(sizeof(int*)**AColSize);
*returnColumnSizes=(int*)malloc(sizeof(int)**AColSize);
*returnSize=*AColSize;
for(int i=0; i<*AColSize; i++) {
num[i]=(int*)malloc(sizeof(int)*ASize);//在每个位置再开辟一个大小为 ASize的数组
(*returnColumnSizes)[i]=ASize;
}
for(int i=0; i<ASize; i++) {
for(int j=0; j<*AColSize; j++) {
num[j][i]=A[i][j];
}
}
return num;
}