From 4552bcf5a4a356415e248dee3b201f0cea7205bb Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Wed, 27 Aug 2025 12:45:33 -0600 Subject: chore: Refactor two_d_arr_init function Return a pointer to a new struct, rather than initialise objects in an existing struct --- max_subarr_remove_conflict_pair.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'max_subarr_remove_conflict_pair.c') diff --git a/max_subarr_remove_conflict_pair.c b/max_subarr_remove_conflict_pair.c index a225f61..8e0d9b3 100644 --- a/max_subarr_remove_conflict_pair.c +++ b/max_subarr_remove_conflict_pair.c @@ -50,11 +50,14 @@ long long maxSubarrays(int n, int **conflictingPairs, int conflictingPairsSize, int main() { int cp1i[2][2] = {{2, 3}, {1, 4}}, cp2i[3][2] = {{1, 2}, {2, 5}, {3, 5}}; - struct two_d_arr cp1, cp2; - two_d_arr_init(&cp1, ARRAY_SIZE(cp1i), ARRAY_SIZE(cp1i[0]), cp1i); - two_d_arr_init(&cp2, ARRAY_SIZE(cp2i), ARRAY_SIZE(cp2i[0]), cp2i); + struct two_d_arr *cp1 = + two_d_arr_init(ARRAY_SIZE(cp1i), ARRAY_SIZE(cp1i[0]), cp1i); + struct two_d_arr *cp2 = + two_d_arr_init(ARRAY_SIZE(cp2i), ARRAY_SIZE(cp2i[0]), cp2i); printf("%lld\n", - maxSubarrays(4, cp1.arr, cp1.row_size, cp1.col_size)); // expect: 9 + maxSubarrays(4, cp1->arr, cp1->row_size, cp1->col_size)); // expect: 9 printf("%lld\n", - maxSubarrays(5, cp2.arr, cp2.row_size, cp2.col_size)); // expect: 12 + maxSubarrays(5, cp2->arr, cp2->row_size, cp2->col_size)); // expect: 12 + two_d_arr_free(cp1); + two_d_arr_free(cp2); } -- cgit v1.2.3