小编ace*_*cer的帖子

如何计算二叉树中的节点总数

我需要计算二叉树中的节点总数.当我执行此代码时,问题就出现了,它为节点总数提供了垃圾值.我的程序输出就像993814.应该是7.

如何解决这个问题?

#include<stdlib.h>
#include<stdio.h>

struct binarytree
{
    int data;
    struct binarytree * right, * left;
};

typedef struct binarytree node;

void insert(node ** tree, int val)
{
    node *temp = NULL;
    if(!(*tree))
    {
        temp = (node *)malloc(sizeof(node));
        temp->left = temp->right = NULL;
        temp->data = val;
        *tree = temp;
        return;
    }

    if(val < (*tree)->data)
    {
        insert(&(*tree)->left, val);
    }
    else if(val > (*tree)->data)
    {
        insert(&(*tree)->right, val);
    }

}

void print_preorder(node * tree)
{
    if (tree)
    {
        printf("%d\n",tree->data);
        print_preorder(tree->left); …
Run Code Online (Sandbox Code Playgroud)

c binary-tree visual-studio-2010 nodes

4
推荐指数
2
解决办法
2万
查看次数

在Bash文件中转义$的字符

我需要创建一个bash文件来重命名文件,我需要有$的文件名符号的.

例如: - Na $ me

如何逃避这个$符号,/无法逃避$符号

bash

2
推荐指数
1
解决办法
45
查看次数

如何在批处理文件中检查变量是否包含特殊字符

如何检查批处理文件中的变量是否包含特殊字符?例如,如果我的变量包含文件名,则文件名不应包含\/ < > | : * " ?此类字符。

@echo off
set param="XXX"
echo %param%| findstr /r "^[^\\/?%*:|"<>\.]*$">nul

if %errorlevel% equ 0 goto :next
echo "Invalid Attribute"

:next
echo correct
Run Code Online (Sandbox Code Playgroud)

我使用此链接作为参考正则表达式来验证文件夹名称和文件名

windows batch-file

2
推荐指数
1
解决办法
6211
查看次数

标签 统计

bash ×1

batch-file ×1

binary-tree ×1

c ×1

nodes ×1

visual-studio-2010 ×1

windows ×1