Bug fixes to C code.

This commit is contained in:
krahets
2023-11-01 05:14:22 +08:00
parent f7dd05e7a4
commit 355cc3a6b1
31 changed files with 246 additions and 219 deletions

View File

@@ -49,6 +49,17 @@ ListNode *getListNode(ListNode *head, int val) {
return head;
}
/* Free the memory allocated to a linked list */
void freeMemoryLinkedList(ListNode *cur) {
// 释放内存
ListNode *pre;
while (cur != NULL) {
pre = cur;
cur = cur->next;
free(pre);
}
}
#ifdef __cplusplus
}
#endif

View File

@@ -95,7 +95,7 @@ void showTrunks(Trunk *trunk) {
}
/* Help to print a binary tree, hide more details */
static void printTreeHelper(TreeNode *node, Trunk *prev, bool isLeft) {
static void printTreeHelper(TreeNode *node, Trunk *prev, bool isRight) {
if (node == NULL) {
return;
}
@@ -104,7 +104,7 @@ static void printTreeHelper(TreeNode *node, Trunk *prev, bool isLeft) {
printTreeHelper(node->right, trunk, true);
if (prev == NULL) {
trunk->str = "———";
} else if (isLeft) {
} else if (isRight) {
trunk->str = "/———";
prev_str = " |";
} else {