69,373
社区成员
发帖
与我相关
我的任务
分享
#include <stdlib.h>
#include <string>
struct node
{
long hashcode;
char *data;
struct node *left;
struct node *right;
};
void node_init(struct node* _this, char* str);
node* node_new(char* str)
{
node* p = (node*)malloc(sizeof(node));
node_init(p, str);
return p;
}
void node_insertleft(struct node* _this, struct node* child)
{
_this->left = child;
}
void node_insertright(struct node* _this, struct node* child)
{
_this->right = child;
}
void node_init(struct node* _this, char* str)
{
_this->left = NULL;
_this->right = NULL;
_this->data = (char*)malloc(strlen(str) + 1);
strcpy(_this->data, str);
}
void node_display(struct node* _this)
{
if(_this != NULL)
{
printf("%s -> ", _this->data);
node_display(_this->left);
node_display(_this->right);
}
}
int main()
{
struct node root;
node_init(&root, "Jack");
struct node* r = node_new("Rose");
node_insertleft(&root, r);
node_insertright(r, node_new("Adie"));
node_insertleft(r, node_new("Bill"));
node_display(&root);
}