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_num_events_attended2.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_num_events_attended2.c')
-rw-r--r-- | max_num_events_attended2.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/max_num_events_attended2.c b/max_num_events_attended2.c index ad9bfdb..f95030a 100644 --- a/max_num_events_attended2.c +++ b/max_num_events_attended2.c @@ -58,14 +58,17 @@ int main() { int e1i[3][3] = {{1, 2, 4}, {3, 4, 3}, {2, 3, 1}}; int e2i[3][3] = {{1, 2, 4}, {3, 4, 3}, {2, 3, 10}}; int e3i[4][3] = {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}, {4, 4, 4}}; - 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", maxValue(e1.arr, e1.row_size, e1.col_size, 2)); // expect: 7 - printf("%d\n", maxValue(e2.arr, e2.row_size, e2.col_size, 2)); // expect: 10 - printf("%d\n", maxValue(e3.arr, e3.row_size, e3.col_size, 3)); // expect: 9 - 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", maxValue(e1->arr, e1->row_size, e1->col_size, 2)); // expect: 7 + printf("%d\n", + maxValue(e2->arr, e2->row_size, e2->col_size, 2)); // expect: 10 + printf("%d\n", maxValue(e3->arr, e3->row_size, e3->col_size, 3)); // expect: 9 + two_d_arr_free(e1); + two_d_arr_free(e2); + two_d_arr_free(e3); } |