mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-08 13:36:06 +00:00
Format the C code in Clang-Format Style: Microsoft
This commit is contained in:
@@ -15,7 +15,7 @@ typedef struct binarySearchTree binarySearchTree;
|
||||
|
||||
int sortIntHelper(const void *a, const void *b) {
|
||||
// 从小到大排序
|
||||
return (*(int *) a - *(int *) b);
|
||||
return (*(int *)a - *(int *)b);
|
||||
}
|
||||
|
||||
/* 构建二叉搜索树 */
|
||||
@@ -33,7 +33,7 @@ TreeNode *buildTree(int nums[], int i, int j) {
|
||||
}
|
||||
|
||||
binarySearchTree *newBinarySearchTree(int nums[], int size) {
|
||||
binarySearchTree *bst = (binarySearchTree *) malloc(sizeof(binarySearchTree));
|
||||
binarySearchTree *bst = (binarySearchTree *)malloc(sizeof(binarySearchTree));
|
||||
TreeNode *root;
|
||||
// 从小到大排序数组
|
||||
qsort(nums, size, sizeof(int), sortIntHelper);
|
||||
@@ -108,7 +108,8 @@ void removeNode(binarySearchTree *bst, int num) {
|
||||
// 循环查找,越过叶节点后跳出
|
||||
while (cur != NULL) {
|
||||
// 找到待删除节点,跳出循环
|
||||
if (cur->val == num) break;
|
||||
if (cur->val == num)
|
||||
break;
|
||||
pre = cur;
|
||||
if (cur->val < num) {
|
||||
// 待删除节点在 root 的右子树中
|
||||
@@ -159,13 +160,11 @@ int main() {
|
||||
TreeNode *node = search(bst, 7);
|
||||
printf("查找到的节点对象的节点值 = %d\n", node->val);
|
||||
|
||||
|
||||
/* 插入节点 */
|
||||
insert(bst, 16);
|
||||
printf("插入节点 16 后,二叉树为\n");
|
||||
printTree(getRoot(bst));
|
||||
|
||||
|
||||
/* 删除节点 */
|
||||
removeNode(bst, 1);
|
||||
printf("删除节点 1 后,二叉树为\n");
|
||||
|
||||
Reference in New Issue
Block a user