mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-13 16:19:46 +08:00
Bug fixes to C code.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user