From 9900e0c668ac68b068387a6117eba78ff6d4b35a Mon Sep 17 00:00:00 2001 From: gonglja <39959756+Gonglja@users.noreply.github.com> Date: Thu, 3 Aug 2023 14:48:10 +0800 Subject: [PATCH] Add array_binary_tree.c and update push_back and pop_back in vector.h (#664) * fix(codes/cpp): Memory leak fix: the space was not freed when pop removed the element. * fix(codes/cpp): Fix access error when printArray(arr, 0) * Update PrintUtil.hpp * fix(codes/c): Fix some errors of cmake build * feat(codes/c): Add hashing_search.c * styles(codes/c): Modify function description * styles(codes/c): Modify binary_search.c code style * fix(codes/c): Fix the problem in binary_tree_bfs.c and the problem that the memory is not released. * feat: Add preorder_traversal_i_compact.c * feat(codes/c): Add head_sort.c * feat(codes/c): Add bucket_sort.c * feat(codes/c): Add binary_search_edge.c * fix(codes/c): Add programs that are not managed by cmake (c code) * feat(codes/c): Add selection_sort.c * style(codes/c): Change swap in selection_sort.c to `selectionSort` * styles(codes/c): Change style. * fix(codes/c): Fix some formatting errors and temporarily remove backtracking chapters * fix(codes/c): Fix space_complexity.c build error. * feat(codes/c): Add array_binary_tree.c * feat(code/c): Update push_back and pop_back in vector.h * styles(codes/c): Adjust format. --------- Co-authored-by: Yudong Jin --- codes/c/chapter_backtracking/permutations_i.c | 15 +- .../preorder_traversal_i_compact.c | 2 +- .../preorder_traversal_ii_compact.c | 6 +- .../preorder_traversal_iii_compact.c | 6 +- .../preorder_traversal_iii_template.c | 14 +- codes/c/chapter_backtracking/subset_sum_i.c | 30 ++-- .../chapter_backtracking/subset_sum_i_naive.c | 19 ++- codes/c/chapter_backtracking/subset_sum_ii.c | 21 +-- codes/c/chapter_tree/CMakeLists.txt | 1 + codes/c/chapter_tree/array_binary_tree.c | 159 ++++++++++++++++++ codes/c/utils/vector.h | 53 +++--- 11 files changed, 247 insertions(+), 79 deletions(-) create mode 100644 codes/c/chapter_tree/array_binary_tree.c diff --git a/codes/c/chapter_backtracking/permutations_i.c b/codes/c/chapter_backtracking/permutations_i.c index fcf78dd5..20d0a934 100644 --- a/codes/c/chapter_backtracking/permutations_i.c +++ b/codes/c/chapter_backtracking/permutations_i.c @@ -12,9 +12,9 @@ void backtrack(vector *state, vector *choices, vector *selected, vector *res) { if (state->size == choices->size) { vector *newState = newVector(); for (int i = 0; i < state->size; i++) { - vectorPushback(newState, state->data[i]); + vectorPushback(newState, state->data[i], sizeof(int)); } - vectorPushback(res, newState); + vectorPushback(res, newState, sizeof(vector)); return; } // 遍历所有选择 @@ -26,7 +26,7 @@ void backtrack(vector *state, vector *choices, vector *selected, vector *res) { if (!select) { // 尝试:做出选择,更新状态 *((bool *)selected->data[i]) = true; - vectorPushback(state, choice); + vectorPushback(state, choice, sizeof(int)); // 进行下一轮选择 backtrack(state, choices, selected, res); // 回退:撤销选择,恢复到之前的状态 @@ -43,7 +43,7 @@ vector *permutationsI(vector *nums) { int select[3] = {false, false, false}; vector *bSelected = newVector(); for (int i = 0; i < nums->size; i++) { - vectorPushback(bSelected, &select[i]); + vectorPushback(bSelected, &select[i], sizeof(int)); } vector *res = newVector(); @@ -55,8 +55,8 @@ vector *permutationsI(vector *nums) { /* 打印向量中的元素 */ void printFunc(vector *v, void *p) { - TreeNode *node = p; - printf("%d", node->val); + int *node = p; + printf("%d", *node); } /* Driver Code */ @@ -64,7 +64,7 @@ int main() { int nums[] = {1, 2, 3}; vector *iNums = newVector(); // int for (int i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) { - vectorPushback(iNums, &nums[i]); + vectorPushback(iNums, &nums[i], sizeof(int)); } vector *res = permutationsI(iNums); @@ -76,6 +76,7 @@ int main() { printVectorMatrix(res, printFunc); // 释放内存 + delVector(iNums); delVector(res); return 0; } diff --git a/codes/c/chapter_backtracking/preorder_traversal_i_compact.c b/codes/c/chapter_backtracking/preorder_traversal_i_compact.c index dd5b0181..dec90b6c 100644 --- a/codes/c/chapter_backtracking/preorder_traversal_i_compact.c +++ b/codes/c/chapter_backtracking/preorder_traversal_i_compact.c @@ -21,7 +21,7 @@ static void preOrder(TreeNode *root) { } if (root->val == 7) { // 记录解 - vectorPushback(res, root); + vectorPushback(res, root, sizeof(int)); } preOrder(root->left); preOrder(root->right); diff --git a/codes/c/chapter_backtracking/preorder_traversal_ii_compact.c b/codes/c/chapter_backtracking/preorder_traversal_ii_compact.c index 2152ecd9..b83b9e71 100644 --- a/codes/c/chapter_backtracking/preorder_traversal_ii_compact.c +++ b/codes/c/chapter_backtracking/preorder_traversal_ii_compact.c @@ -12,14 +12,14 @@ void preOrder(TreeNode *root, vector *path, vector *res) { return; } // 尝试 - vectorPushback(path, root); + vectorPushback(path, root, sizeof(TreeNode)); if (root->val == 7) { // 记录解 vector *newPath = newVector(); for (int i = 0; i < path->size; i++) { - vectorPushback(newPath, path->data[i]); + vectorPushback(newPath, path->data[i], sizeof(int)); } - vectorPushback(res, newPath); + vectorPushback(res, newPath, sizeof(vector)); } preOrder(root->left, path, res); diff --git a/codes/c/chapter_backtracking/preorder_traversal_iii_compact.c b/codes/c/chapter_backtracking/preorder_traversal_iii_compact.c index f0d5aea2..95a2cc23 100644 --- a/codes/c/chapter_backtracking/preorder_traversal_iii_compact.c +++ b/codes/c/chapter_backtracking/preorder_traversal_iii_compact.c @@ -13,14 +13,14 @@ void preOrder(TreeNode *root, vector *path, vector *res) { return; } // 尝试 - vectorPushback(path, root); + vectorPushback(path, root, sizeof(TreeNode)); if (root->val == 7) { // 记录解 vector *newPath = newVector(); for (int i = 0; i < path->size; i++) { - vectorPushback(newPath, path->data[i]); + vectorPushback(newPath, path->data[i], sizeof(int)); } - vectorPushback(res, newPath); + vectorPushback(res, newPath, sizeof(vector)); res->depth++; } diff --git a/codes/c/chapter_backtracking/preorder_traversal_iii_template.c b/codes/c/chapter_backtracking/preorder_traversal_iii_template.c index d1216d3a..eb82b8db 100644 --- a/codes/c/chapter_backtracking/preorder_traversal_iii_template.c +++ b/codes/c/chapter_backtracking/preorder_traversal_iii_template.c @@ -15,9 +15,9 @@ bool isSolution(vector *state) { void recordSolution(vector *state, vector *res) { vector *newPath = newVector(); for (int i = 0; i < state->size; i++) { - vectorPushback(newPath, state->data[i]); + vectorPushback(newPath, state->data[i], sizeof(int)); } - vectorPushback(res, newPath); + vectorPushback(res, newPath, sizeof(vector)); } /* 判断在当前状态下,该选择是否合法 */ @@ -27,7 +27,7 @@ bool isValid(vector *state, TreeNode *choice) { /* 更新状态 */ void makeChoice(vector *state, TreeNode *choice) { - vectorPushback(state, choice); + vectorPushback(state, choice, sizeof(TreeNode)); } /* 恢复状态 */ @@ -52,8 +52,8 @@ void backtrack(vector *state, vector *choices, vector *res) { makeChoice(state, choice); // 进行下一轮选择 vector *nextChoices = newVector(); - vectorPushback(nextChoices, choice->left); - vectorPushback(nextChoices, choice->right); + vectorPushback(nextChoices, choice->left, sizeof(TreeNode)); + vectorPushback(nextChoices, choice->right, sizeof(TreeNode)); backtrack(state, nextChoices, res); // 回退:撤销选择,恢复到之前的状态 undoChoice(state, choice); @@ -79,7 +79,7 @@ int main() { vector *state = newVector(); vector *choices = newVector(); vector *res = newVector(); - vectorPushback(choices, root); + vectorPushback(choices, root, sizeof(TreeNode)); backtrack(state, choices, res); printf("输出所有根节点到节点 7 的路径,要求路径中不包含值为 3 的节点:\n"); @@ -88,7 +88,7 @@ int main() { vector *vals = newVector(); for (int j = 0; j < path->size; j++) { TreeNode *node = path->data[j]; - vectorPushback(vals, &node->val); + vectorPushback(vals, &node->val, sizeof(int)); } printVector(vals, printFunc); } diff --git a/codes/c/chapter_backtracking/subset_sum_i.c b/codes/c/chapter_backtracking/subset_sum_i.c index 8d2b23b7..0284841a 100644 --- a/codes/c/chapter_backtracking/subset_sum_i.c +++ b/codes/c/chapter_backtracking/subset_sum_i.c @@ -12,9 +12,9 @@ void backtrack(vector *state, int target, vector *choices, int start, vector *re if (target == 0) { vector *tmpVector = newVector(); for (int i = 0; i < state->size; i++) { - vectorPushback(tmpVector, state->data[i]); + vectorPushback(tmpVector, state->data[i], sizeof(int)); } - vectorPushback(res, tmpVector); + vectorPushback(res, tmpVector, sizeof(vector)); return; } // 遍历所有选择 @@ -22,10 +22,10 @@ void backtrack(vector *state, int target, vector *choices, int start, vector *re for (int i = start; i < choices->size; i++) { // 剪枝:若子集和超过 target ,则跳过该选择 if (target - *(int *)(choices->data[i]) < 0) { - continue; + break; } // 尝试:做出选择,更新 target, start - vectorPushback(state, choices->data[i]); + vectorPushback(state, choices->data[i], sizeof(int)); // 进行下一轮选择 backtrack(state, target - *(int *)(choices->data[i]), choices, i, res); // 回退:撤销选择,恢复到之前的状态 @@ -40,37 +40,39 @@ int comp(const void *a, const void *b) { /* 求解子集和 I */ vector *subsetSumI(vector *nums, int target) { - vector *state = newVector(); // 状态(子集) - qsort(nums->data[0], nums->size, sizeof(int), comp); // 对 nums 进行排序 - int start = 0; // 子集和 - vector *res = newVector(); // 结果列表(子集列表) + vector *state = newVector(); // 状态(子集) + qsort(nums->data, nums->size, sizeof(int *), comp); // 对 nums 进行排序 + int start = 0; // 子集和 + vector *res = newVector(); // 结果列表(子集列表) backtrack(state, target, nums, start, res); return res; } /* 打印向量中的元素 */ void printFunc(vector *v, void *p) { - TreeNode *node = p; - printf("%d", node->val); + int *node = p; + printf("%d", *node); } /* Driver Code */ int main() { int nums[] = {3, 4, 5}; - vector *vNums = newVector(); + vector *iNums = newVector(); for (int i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) { - vectorPushback(vNums, &nums[i]); + vectorPushback(iNums, &nums[i], sizeof(int)); } + int target = 9; - vector *res = subsetSumI(vNums, target); + vector *res = subsetSumI(iNums, target); printf("输入数组 nums = "); - printVector(vNums, printFunc); + printVector(iNums, printFunc); printf("target = %d\n", target); printf("所有和等于 %d 的子集 res = \r\n", target); printVectorMatrix(res, printFunc); + delVector(iNums); delVector(res); return 0; } diff --git a/codes/c/chapter_backtracking/subset_sum_i_naive.c b/codes/c/chapter_backtracking/subset_sum_i_naive.c index b4587256..cf270f6e 100644 --- a/codes/c/chapter_backtracking/subset_sum_i_naive.c +++ b/codes/c/chapter_backtracking/subset_sum_i_naive.c @@ -12,9 +12,9 @@ void backtrack(vector *state, int target, int total, vector *choices, vector *re if (total == target) { vector *tmpVector = newVector(); for (int i = 0; i < state->size; i++) { - vectorPushback(tmpVector, state->data[i]); + vectorPushback(tmpVector, state->data[i], sizeof(int)); } - vectorPushback(res, tmpVector); + vectorPushback(res, tmpVector, sizeof(vector)); return; } // 遍历所有选择 @@ -24,7 +24,7 @@ void backtrack(vector *state, int target, int total, vector *choices, vector *re continue; } // 尝试:做出选择,更新元素和 total - vectorPushback(state, choices->data[i]); + vectorPushback(state, choices->data[i], sizeof(int)); // 进行下一轮选择 backtrack(state, target, total + *(int *)(choices->data[i]), choices, res); // 回退:撤销选择,恢复到之前的状态 @@ -43,27 +43,28 @@ vector *subsetSumINaive(vector *nums, int target) { /* 打印向量中的元素 */ void printFunc(vector *v, void *p) { - TreeNode *node = p; - printf("%d", node->val); + int *node = p; + printf("%d", *node); } /* Driver Code */ int main() { int nums[] = {3, 4, 5}; - vector *vNums = newVector(); + vector *iNums = newVector(); for (int i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) { - vectorPushback(vNums, &nums[i]); + vectorPushback(iNums, &nums[i], sizeof(int)); } int target = 9; - vector *res = subsetSumINaive(vNums, target); + vector *res = subsetSumINaive(iNums, target); printf("输入数组 nums = "); - printVector(vNums, printFunc); + printVector(iNums, printFunc); printf("target = %d\n", target); printf("所有和等于 %d 的子集 res = \r\n", target); printVectorMatrix(res, printFunc); + delVector(iNums); delVector(res); return 0; } diff --git a/codes/c/chapter_backtracking/subset_sum_ii.c b/codes/c/chapter_backtracking/subset_sum_ii.c index df9b9b85..54670d52 100644 --- a/codes/c/chapter_backtracking/subset_sum_ii.c +++ b/codes/c/chapter_backtracking/subset_sum_ii.c @@ -12,9 +12,9 @@ void backtrack(vector *state, int target, vector *choices, int start, vector *re if (target == 0) { vector *tmpVector = newVector(); for (int i = 0; i < state->size; i++) { - vectorPushback(tmpVector, state->data[i]); + vectorPushback(tmpVector, state->data[i], sizeof(int)); } - vectorPushback(res, tmpVector); + vectorPushback(res, tmpVector, sizeof(vector)); return; } // 遍历所有选择 @@ -31,7 +31,7 @@ void backtrack(vector *state, int target, vector *choices, int start, vector *re continue; } // 尝试:做出选择,更新 target, start - vectorPushback(state, choices->data[i]); + vectorPushback(state, choices->data[i], sizeof(int)); // 进行下一轮选择 backtrack(state, target - *(int *)(choices->data[i]), choices, i + 1, res); // 回退:撤销选择,恢复到之前的状态 @@ -47,7 +47,7 @@ int comp(const void *a, const void *b) { /* 求解子集和 II */ vector *subsetSumII(vector *nums, int target) { vector *state = newVector(); // 状态(子集) - qsort(nums->data[0], nums->size, sizeof(int), comp); // 对 nums 进行排序 + qsort(nums->data, nums->size, sizeof(int *), comp); // 对 nums 进行排序 int start = 0; // 子集和 vector *res = newVector(); // 结果列表(子集列表) backtrack(state, target, nums, start, res); @@ -56,27 +56,28 @@ vector *subsetSumII(vector *nums, int target) { /* 打印向量中的元素 */ void printFunc(vector *v, void *p) { - TreeNode *node = p; - printf("%d", node->val); + int *node = p; + printf("%d", *node); } /* Driver Code */ int main() { int nums[] = {4, 4, 5}; - vector *vNums = newVector(); + vector *iNums = newVector(); for (int i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) { - vectorPushback(vNums, &nums[i]); + vectorPushback(iNums, &nums[i], sizeof(int)); } int target = 9; - vector *res = subsetSumII(vNums, target); + vector *res = subsetSumII(iNums, target); printf("输入数组 nums = "); - printVector(vNums, printFunc); + printVector(iNums, printFunc); printf("target = %d\n", target); printf("所有和等于 %d 的子集 res = \r\n", target); printVectorMatrix(res, printFunc); + delVector(iNums); delVector(res); return 0; } diff --git a/codes/c/chapter_tree/CMakeLists.txt b/codes/c/chapter_tree/CMakeLists.txt index 287e849b..9b4e825f 100644 --- a/codes/c/chapter_tree/CMakeLists.txt +++ b/codes/c/chapter_tree/CMakeLists.txt @@ -3,3 +3,4 @@ add_executable(binary_tree binary_tree.c) add_executable(binary_tree_bfs binary_tree_bfs.c) add_executable(binary_tree_dfs binary_tree_dfs.c) add_executable(binary_search_tree binary_search_tree.c) +add_executable(array_binary_tree array_binary_tree.c) diff --git a/codes/c/chapter_tree/array_binary_tree.c b/codes/c/chapter_tree/array_binary_tree.c new file mode 100644 index 00000000..7cbadbda --- /dev/null +++ b/codes/c/chapter_tree/array_binary_tree.c @@ -0,0 +1,159 @@ +/** + * File: array_binary_tree.c + * Created Time: 2023-07-29 + * Author: Gonglja (glj0@outlook.com) + */ + +#include "../utils/common.h" + +struct arrayBinaryTree { + vector *tree; +}; + +typedef struct arrayBinaryTree arrayBinaryTree; + +arrayBinaryTree *newArrayBinaryTree(vector *arr) { + arrayBinaryTree *newABT = malloc(sizeof(arrayBinaryTree)); + newABT->tree = arr; + return newABT; +} + +/* 节点数量 */ +int size(arrayBinaryTree *abt) { + return abt->tree->size; +} + +/* 获取索引为 i 节点的值 */ +int val(arrayBinaryTree *abt, int i) { + // 若索引越界,则返回 INT_MAX ,代表空位 + if (i < 0 || i >= size(abt)) + return INT_MAX; + return *(int *)abt->tree->data[i]; +} + +/* 获取索引为 i 节点的左子节点的索引 */ +int left(int i) { + return 2 * i + 1; +} + +/* 获取索引为 i 节点的右子节点的索引 */ +int right(int i) { + return 2 * i + 2; +} + +/* 获取索引为 i 节点的父节点的索引 */ +int parent(int i) { + return (i - 1) / 2; +} + +/* 深度优先遍历 */ +void dfs(arrayBinaryTree *abt, int i, const char *order, vector *res) { + // 若为空位,则返回 + if (val(abt, i) == INT_MAX) + return; + // 前序遍历 + if (strcmp(order, "pre") == 0) { + int tmp = val(abt, i); + vectorPushback(res, &tmp, sizeof(tmp)); + } + dfs(abt, left(i), order, res); + // 中序遍历 + if (strcmp(order, "in") == 0) { + int tmp = val(abt, i); + vectorPushback(res, &tmp, sizeof(tmp)); + } + dfs(abt, right(i), order, res); + // 后序遍历 + if (strcmp(order, "post") == 0) { + int tmp = val(abt, i); + vectorPushback(res, &tmp, sizeof(tmp)); + } +} + +/* 层序遍历 */ +vector *levelOrder(arrayBinaryTree *abt) { + vector *res = newVector(); + // 直接遍历数组 + for (int i = 0; i < size(abt); i++) { + if (val(abt, i) != INT_MAX) { + int tmp = val(abt, i); + vectorPushback(res, &tmp, sizeof(int)); + } + } + return res; +} + +/* 前序遍历 */ +vector *preOrder(arrayBinaryTree *abt) { + vector *res = newVector(); + dfs(abt, 0, "pre", res); + return res; +} + +/* 中序遍历 */ +vector *inOrder(arrayBinaryTree *abt) { + vector *res = newVector(); + dfs(abt, 0, "in", res); + return res; +} + +/* 后序遍历 */ +vector *postOrder(arrayBinaryTree *abt) { + vector *res = newVector(); + dfs(abt, 0, "post", res); + return res; +} + +/* 打印向量中的元素 */ +void printFunc(vector *v, void *p) { + int *val = p; + printf("%d", *val); +} + +/* Driver Code */ +int main() { + // 初始化二叉树 + // 使用 INT_MAX 代表空位 nullptr + int arr[] = {1, 2, 3, 4, INT_MAX, 6, 7, 8, 9, INT_MAX, INT_MAX, 12, INT_MAX, INT_MAX, 15}; + TreeNode *root = arrToTree(arr, sizeof(arr) / sizeof(arr[0])); + printf("\n初始化二叉树\n"); + printf("二叉树的数组表示:\n"); + printArray(arr, sizeof(arr) / sizeof(arr[0])); + printf("二叉树的链表表示:\n"); + printTree(root); + + vector *vArr = newVector(); + for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) { + vectorPushback(vArr, &arr[i], sizeof(int)); + } + // 数组表示下的二叉树类 + arrayBinaryTree *abt = newArrayBinaryTree(vArr); + + // 访问节点 + int i = 1; + int l = left(i), r = right(i), p = parent(i); + printf("\n当前节点的索引为 %d,值为 %d\n", i, val(abt, i)); + printf("其左子节点的索引为 %d,值为 %d\r\n", l, val(abt, l)); + printf("其右子节点的索引为 %d,值为 %d\r\n", r, val(abt, r)); + printf("其父节点的索引为 %d,值为 %d\r\n", p, val(abt, p)); + + // 遍历树 + vector *res = levelOrder(abt); + printf("\n层序遍历为: "); + printVector(res, printFunc); + delVector(res); + res = preOrder(abt); + printf("前序遍历为: "); + printVector(res, printFunc); + delVector(res); + res = inOrder(abt); + printf("中序遍历为: "); + printVector(res, printFunc); + delVector(res); + res = postOrder(abt); + printf("后序遍历为: "); + printVector(res, printFunc); + delVector(res); + + return 0; +} \ No newline at end of file diff --git a/codes/c/utils/vector.h b/codes/c/utils/vector.h index 74d5c4dc..39bbf65d 100644 --- a/codes/c/utils/vector.h +++ b/codes/c/utils/vector.h @@ -48,18 +48,21 @@ void delVector(vector *v) { } } -/* 添加元素到向量尾部 */ -void vectorPushback(vector *v, void *elem) { +/* 添加元素(拷贝方式)到向量尾部 */ +void vectorPushback(vector *v, void *elem, int elemSize) { if (v->size == v->capacity) { v->capacity *= 2; v->data = realloc(v->data, v->capacity * sizeof(void *)); } - v->data[v->size++] = elem; + void *tmp = malloc(sizeof(char) * elemSize); + memcpy(tmp, elem, elemSize); + v->data[v->size++] = tmp; } /* 从向量尾部弹出元素 */ void vectorPopback(vector *v) { if (v->size != 0) { + free(v->data[v->size - 1]); v->size--; } } @@ -96,15 +99,15 @@ void printVector(vector *v, void (*printFunc)(vector *v, void *p)) { return; } else if (v->depth == 1) { for (int i = 0; i < v->size; i++) { - if (i == 0) { - printf("["); - } else if (i == v->size-1) { - printFunc(v, v->data[i]); - printf("]\r\n"); - break; - } - printFunc(v, v->data[i]); - printf(","); + if (i == 0) { + printf("["); + } else if (i == v->size - 1) { + printFunc(v, v->data[i]); + printf("]\r\n"); + break; + } + printFunc(v, v->data[i]); + printf(","); } } else { for (int i = 0; i < v->size; i++) { @@ -117,19 +120,19 @@ void printVector(vector *v, void (*printFunc)(vector *v, void *p)) { /* 当前仅支持打印深度为 2 的 vector */ void printVectorMatrix(vector *vv, void (*printFunc)(vector *v, void *p)) { - printf("[\n"); - for (int i = 0; i < vv->size; i++) { - vector *v = (vector *)vv->data[i]; - printf(" ["); - for (int j = 0; j < v->size; j++) { - printFunc(v, v->data[j]); - if (j != v->size -1) - printf(","); - } - printf("],"); - printf("\n"); - } - printf("]\n"); + printf("[\n"); + for (int i = 0; i < vv->size; i++) { + vector *v = (vector *)vv->data[i]; + printf(" ["); + for (int j = 0; j < v->size; j++) { + printFunc(v, v->data[j]); + if (j != v->size - 1) + printf(","); + } + printf("],"); + printf("\n"); + } + printf("]\n"); } #ifdef __cplusplus