aboutsummaryrefslogtreecommitdiff
path: root/find_good_subset_matrix.c
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-08-27 12:45:33 -0600
committerJack Sangdahl <[email protected]>2025-08-27 12:45:33 -0600
commit4552bcf5a4a356415e248dee3b201f0cea7205bb (patch)
tree9868465918c6a6841b84cd14d66923b993dd9d62 /find_good_subset_matrix.c
parentf549305fb5ca531d29dce6c2c091560f44190443 (diff)
downloadleetcode-4552bcf5a4a356415e248dee3b201f0cea7205bb.tar.gz
leetcode-4552bcf5a4a356415e248dee3b201f0cea7205bb.zip
chore: Refactor two_d_arr_init function
Return a pointer to a new struct, rather than initialise objects in an existing struct
Diffstat (limited to 'find_good_subset_matrix.c')
-rw-r--r--find_good_subset_matrix.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/find_good_subset_matrix.c b/find_good_subset_matrix.c
index aadf5ce..26d704e 100644
--- a/find_good_subset_matrix.c
+++ b/find_good_subset_matrix.c
@@ -64,16 +64,15 @@ int main() {
int g1i[3][4] = {{0, 1, 1, 0}, {0, 0, 0, 1}, {1, 1, 1, 1}}, rs1;
int g2i[1][1] = {{0}}, rs2;
int g3i[2][3] = {{1, 1, 1}, {1, 1, 1}}, rs3;
- struct two_d_arr g1, g2, g3;
- two_d_arr_init(&g1, 3, 4, g1i);
- two_d_arr_init(&g2, 1, 1, g2i);
- two_d_arr_init(&g3, 2, 3, g3i);
+ struct two_d_arr *g1 = two_d_arr_init(3, 4, g1i);
+ struct two_d_arr *g2 = two_d_arr_init(1, 1, g2i);
+ struct two_d_arr *g3 = two_d_arr_init(2, 3, g3i);
int *gsobm1 =
- goodSubsetofBinaryMatrix(g1.arr, g1.row_size, g1.col_size, &rs1);
+ goodSubsetofBinaryMatrix(g1->arr, g1->row_size, g1->col_size, &rs1);
int *gsobm2 =
- goodSubsetofBinaryMatrix(g2.arr, g2.row_size, g2.col_size, &rs2);
+ goodSubsetofBinaryMatrix(g2->arr, g2->row_size, g2->col_size, &rs2);
int *gsobm3 =
- goodSubsetofBinaryMatrix(g3.arr, g3.row_size, g3.col_size, &rs3);
+ goodSubsetofBinaryMatrix(g3->arr, g3->row_size, g3->col_size, &rs3);
for (int i = 0; i < rs1; i++)
printf("%d ", gsobm1[i]); // expect: 0 1
printf("\n");
@@ -83,7 +82,7 @@ int main() {
for (int i = 0; i < rs3; i++)
printf("%d ", gsobm3[i]); // expect: null
printf("\n");
- free(gsobm1), two_d_arr_free(&g1);
- free(gsobm2), two_d_arr_free(&g2);
- free(gsobm3), two_d_arr_free(&g3);
+ free(gsobm1), two_d_arr_free(g1);
+ free(gsobm2), two_d_arr_free(g2);
+ free(gsobm3), two_d_arr_free(g3);
}