Fine tune the C codes.

This commit is contained in:
krahets
2023-04-17 22:15:06 +08:00
parent c4ea4e39f3
commit af0f92c18d
15 changed files with 29 additions and 103 deletions

View File

@@ -28,12 +28,7 @@ ListNode *newListNode(int val) {
return node;
}
/**
* @brief Generate a linked list with a vector
*
* @param list
* @return ListNode*
*/
/* Generate a linked list with a vector */
ListNode *arrToLinkedList(const int *arr, size_t size) {
if (size <= 0) {
return NULL;
@@ -48,13 +43,7 @@ ListNode *arrToLinkedList(const int *arr, size_t size) {
return dummy->next;
}
/**
* @brief Get a list node with specific value from a linked list
*
* @param head
* @param val
* @return ListNode*
*/
/* Get a list node with specific value from a linked list */
ListNode *getListNode(ListNode *head, int val) {
while (head != NULL && head->val != val) {
head = head->next;

View File

@@ -18,12 +18,7 @@
extern "C" {
#endif
/**
* @brief Print an Array
*
* @param arr
* @param size
*/
/* Print an Array */
static void printArray(int arr[], int size) {
printf("[");
if (arr != NULL && size != 0) {
@@ -44,11 +39,7 @@ static void printArray(int arr[], int size) {
}
}
/**
* @brief Print a linked list
*
* @param head
*/
/* Print a linked list */
static void printLinkedList(ListNode *node) {
if (node == NULL) {
return;
@@ -75,11 +66,7 @@ Trunk *newTrunk(Trunk *prev, char *str) {
return trunk;
}
/**
* @brief Helper function to print branches of the binary tree
*
* @param trunk
*/
/* Helper function to print branches of the binary tree */
void showTrunks(Trunk *trunk) {
if (trunk == NULL) {
return;
@@ -88,12 +75,7 @@ void showTrunks(Trunk *trunk) {
printf("%s", trunk->str);
}
/**
* Help to print a binary tree, hide more details
* @param node
* @param prev
* @param isLeft
*/
/* Help to print a binary tree, hide more details */
static void printTreeHelper(TreeNode *node, Trunk *prev, bool isLeft) {
if (node == NULL) {
return;
@@ -121,21 +103,12 @@ static void printTreeHelper(TreeNode *node, Trunk *prev, bool isLeft) {
printTreeHelper(node->left, trunk, false);
}
/**
* @brief Print a binary tree
*
* @param head
*/
/* Print a binary tree */
static void printTree(TreeNode *root) {
printTreeHelper(root, NULL, false);
}
/**
* @brief Print a Heap
*
* @param arr
* @param size
*/
/* Print a Heap */
static void printHeap(int arr[], int size) {
TreeNode *root;
printf("堆的数组表示:");

View File

@@ -34,13 +34,7 @@ TreeNode *newTreeNode(int val) {
return node;
}
/**
* @brief Generate a binary tree with an array
*
* @param arr
* @param size
* @return TreeNode *
*/
/* Generate a binary tree with an array */
TreeNode *arrToTree(const int *arr, size_t size) {
if (size <= 0) {
return NULL;
@@ -81,13 +75,7 @@ TreeNode *arrToTree(const int *arr, size_t size) {
return root;
}
/**
* @brief Generate a binary tree with an array
*
* @param arr
* @param size
* @return TreeNode *
*/
/* Generate a binary tree with an array */
int *treeToArr(TreeNode *root) {
if (root == NULL) {
return NULL;