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 /grid_game.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 'grid_game.c')
-rw-r--r-- | grid_game.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/grid_game.c b/grid_game.c index 1945c92..88d69a1 100644 --- a/grid_game.c +++ b/grid_game.c @@ -32,14 +32,16 @@ int main() { int g1i[2][3] = {{2, 5, 4}, {1, 5, 1}}; int g2i[2][3] = {{3, 3, 1}, {8, 5, 2}}; int g3i[2][4] = {{1, 3, 1, 15}, {1, 3, 3, 1}}; - struct two_d_arr g1, g2, g3; - two_d_arr_init(&g1, ARRAY_SIZE(g1i), ARRAY_SIZE(g1i[0]), g1i); - two_d_arr_init(&g2, ARRAY_SIZE(g2i), ARRAY_SIZE(g2i[0]), g2i); - two_d_arr_init(&g3, ARRAY_SIZE(g3i), ARRAY_SIZE(g3i[0]), g3i); - printf("%lld\n", gridGame(g1.arr, g1.row_size, g1.col_size)); // expect: 4 - printf("%lld\n", gridGame(g2.arr, g2.row_size, g2.col_size)); // expect: 4 - printf("%lld\n", gridGame(g3.arr, g3.row_size, g3.col_size)); // expect: 7 - two_d_arr_free(&g1); - two_d_arr_free(&g2); - two_d_arr_free(&g3); + struct two_d_arr *g1 = + two_d_arr_init(ARRAY_SIZE(g1i), ARRAY_SIZE(g1i[0]), g1i); + struct two_d_arr *g2 = + two_d_arr_init(ARRAY_SIZE(g2i), ARRAY_SIZE(g2i[0]), g2i); + struct two_d_arr *g3 = + two_d_arr_init(ARRAY_SIZE(g3i), ARRAY_SIZE(g3i[0]), g3i); + printf("%lld\n", gridGame(g1->arr, g1->row_size, g1->col_size)); // expect: 4 + printf("%lld\n", gridGame(g2->arr, g2->row_size, g2->col_size)); // expect: 4 + printf("%lld\n", gridGame(g3->arr, g3->row_size, g3->col_size)); // expect: 7 + two_d_arr_free(g1); + two_d_arr_free(g2); + two_d_arr_free(g3); } |