aboutsummaryrefslogtreecommitdiff
path: root/count_num_complete_component.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 /count_num_complete_component.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 'count_num_complete_component.c')
-rw-r--r--count_num_complete_component.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/count_num_complete_component.c b/count_num_complete_component.c
index a6ede23..8051246 100644
--- a/count_num_complete_component.c
+++ b/count_num_complete_component.c
@@ -61,13 +61,14 @@ int countCompleteComponents(int n, int **edges, int edgesSize,
int main() {
int e1i[4][2] = {{0, 1}, {0, 2}, {1, 2}, {3, 4}},
e2i[5][2] = {{0, 1}, {0, 2}, {1, 2}, {3, 4}, {3, 5}};
- struct two_d_arr e1, e2;
- two_d_arr_init(&e1, ARRAY_SIZE(e1i), ARRAY_SIZE(e1i[0]), e1i);
- two_d_arr_init(&e2, ARRAY_SIZE(e2i), ARRAY_SIZE(e2i[0]), e2i);
- printf("%d\n", countCompleteComponents(6, e1.arr, e1.row_size,
- e1.col_size)); // expect: 3
- printf("%d\n", countCompleteComponents(6, e2.arr, e2.row_size,
- e2.col_size)); // expect: 1
- two_d_arr_free(&e1);
- two_d_arr_free(&e2);
+ struct two_d_arr *e1 =
+ two_d_arr_init(ARRAY_SIZE(e1i), ARRAY_SIZE(e1i[0]), e1i);
+ struct two_d_arr *e2 =
+ two_d_arr_init(ARRAY_SIZE(e2i), ARRAY_SIZE(e2i[0]), e2i);
+ printf("%d\n", countCompleteComponents(6, e1->arr, e1->row_size,
+ e1->col_size)); // expect: 3
+ printf("%d\n", countCompleteComponents(6, e2->arr, e2->row_size,
+ e2->col_size)); // expect: 1
+ two_d_arr_free(e1);
+ two_d_arr_free(e2);
}