aboutsummaryrefslogtreecommitdiff
path: root/cycle_queries_tree.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 /cycle_queries_tree.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 'cycle_queries_tree.c')
-rw-r--r--cycle_queries_tree.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/cycle_queries_tree.c b/cycle_queries_tree.c
index d604e9f..444744d 100644
--- a/cycle_queries_tree.c
+++ b/cycle_queries_tree.c
@@ -35,11 +35,12 @@ int *cycleLengthQueries(int n, int **queries, int queriesSize,
int main() {
int q1i[3][2] = {{5, 3}, {4, 7}, {2, 3}}, rs1;
int q2i[1][2] = {{1, 2}}, rs2;
- struct two_d_arr q1, q2;
- two_d_arr_init(&q1, ARRAY_SIZE(q1i), ARRAY_SIZE(q1i[0]), q1i);
- two_d_arr_init(&q2, ARRAY_SIZE(q2i), ARRAY_SIZE(q2i[0]), q2i);
- int *clq1 = cycleLengthQueries(3, q1.arr, q1.row_size, q1.col_size, &rs1);
- int *clq2 = cycleLengthQueries(2, q2.arr, q2.row_size, q2.col_size, &rs2);
+ struct two_d_arr *q1 =
+ two_d_arr_init(ARRAY_SIZE(q1i), ARRAY_SIZE(q1i[0]), q1i);
+ struct two_d_arr *q2 =
+ two_d_arr_init(ARRAY_SIZE(q2i), ARRAY_SIZE(q2i[0]), q2i);
+ int *clq1 = cycleLengthQueries(3, q1->arr, q1->row_size, q1->col_size, &rs1);
+ int *clq2 = cycleLengthQueries(2, q2->arr, q2->row_size, q2->col_size, &rs2);
for (int i = 0; i < rs1; i++)
printf("%d ", clq1[i]); // expect: 4 5 3
printf("\n");
@@ -48,6 +49,6 @@ int main() {
printf("\n");
free(clq1);
free(clq2);
- two_d_arr_free(&q1);
- two_d_arr_free(&q2);
+ two_d_arr_free(q1);
+ two_d_arr_free(q2);
}