diff options
author | Jack Sangdahl <[email protected]> | 2025-08-27 12:45:33 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-08-27 12:45:33 -0600 |
commit | 4552bcf5a4a356415e248dee3b201f0cea7205bb (patch) | |
tree | 9868465918c6a6841b84cd14d66923b993dd9d62 /max_path_quality_graph.c | |
parent | f549305fb5ca531d29dce6c2c091560f44190443 (diff) | |
download | leetcode-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 'max_path_quality_graph.c')
-rw-r--r-- | max_path_quality_graph.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/max_path_quality_graph.c b/max_path_quality_graph.c index 9d3fc52..4700a46 100644 --- a/max_path_quality_graph.c +++ b/max_path_quality_graph.c @@ -75,17 +75,19 @@ int main() { int v2[] = {5, 10, 15, 20}, e2i[3][3] = {{0, 1, 10}, {1, 2, 10}, {0, 3, 10}}; int v3[] = {1, 2, 3, 4}, e3i[4][3] = {{0, 1, 10}, {1, 2, 11}, {2, 3, 12}, {1, 3, 13}}; - struct two_d_arr e1, e2, e3; - 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); - two_d_arr_init(&e3, ARRAY_SIZE(e3i), ARRAY_SIZE(e3i[0]), e3i); - printf("%d\n", maximalPathQuality(v1, ARRAY_SIZE(v1), e1.arr, e1.row_size, - e1.col_size, 49)); // expect: 75 - printf("%d\n", maximalPathQuality(v1, ARRAY_SIZE(v1), e1.arr, e1.row_size, - e1.col_size, 30)); // expect: 25 - printf("%d\n", maximalPathQuality(v1, ARRAY_SIZE(v1), e1.arr, e1.row_size, - e1.col_size, 50)); // expect: 50 - two_d_arr_free(&e1); - two_d_arr_free(&e2); - two_d_arr_free(&e3); + 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); + struct two_d_arr *e3 = + two_d_arr_init(ARRAY_SIZE(e3i), ARRAY_SIZE(e3i[0]), e3i); + printf("%d\n", maximalPathQuality(v1, ARRAY_SIZE(v1), e1->arr, e1->row_size, + e1->col_size, 49)); // expect: 75 + printf("%d\n", maximalPathQuality(v1, ARRAY_SIZE(v1), e1->arr, e1->row_size, + e1->col_size, 30)); // expect: 25 + printf("%d\n", maximalPathQuality(v1, ARRAY_SIZE(v1), e1->arr, e1->row_size, + e1->col_size, 50)); // expect: 50 + two_d_arr_free(e1); + two_d_arr_free(e2); + two_d_arr_free(e3); } |