struct tree {
char info;
struct tree* left;
struct tree* right;
};
typedef struct tree Tree;
Tree* address = NULL; // How to remove this global variable?
void nodeAddress (Tree* a, char v) {
if (a != NULL) {
nodeAddress(a->left, v);
if (a->info == v) address = a;
nodeAddress(a->right, v);
}
}发布于 2022-06-24 16:26:14
我同意上面的说法,你应该简单地使用return。
还可以考虑对指针使用另一层抽象,这完全是个人选择的问题。我个人认为这种类型的指针类型定义使代码更加清晰:
struct tree;
typedef struct tree *Position;
typedef struct tree
{
char info;
Position left;
Position right;
} Tree; https://stackoverflow.com/questions/72746047
复制相似问题