我需要计算二叉树中的节点总数.当我执行此代码时,问题就出现了,它为节点总数提供了垃圾值.我的程序输出就像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) 我需要创建一个bash文件来重命名文件,我需要有$的文件名符号的.
例如: - Na $ me
如何逃避这个$符号,/无法逃避$符号
如何检查批处理文件中的变量是否包含特殊字符?例如,如果我的变量包含文件名,则文件名不应包含\/ < > | : * " ?此类字符。
@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)
我使用此链接作为参考正则表达式来验证文件夹名称和文件名