我试图比较两个字符串,看看它作为根节点的叶节点应该去哪里,所以第四个。我一直尝试使用字符串比较,但出现错误。我对 c 中的二叉树非常不熟悉,需要插入节点的帮助。
这是我迄今为止遇到的错误代码:
#include <stdio.h>
#include <stdlib.h>
#define MAXLEN 15
typedef struct treeNode{
char string[MAXLEN+1];
struct treeNode *left;
struct treNode *right;
}treeNode;
treeNode * insert(treeNode *node, char s[MAXLEN+1]){
if(node == NULL){
treeNode *temp;
temp = (treeNode *)malloc(sizeof(treeNode));
strncpy(temp -> string, s, sizeof(treeNode));
temp -> left = NULL;
temp -> right = NULL;
return temp;
}
else-if(strcmp(node->string,char s)>0){
}
}
最佳答案
您的程序目前存在三个问题:
“else-if”应为“else if”
strcmp(node->string,char s) 应该是 strcmp(node->string, s)
没有主方法
关于c - 如何比较二叉搜索树的两个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28511976/