作者sakurarain (茫然不知所以)
看板C_and_CPP
标题[问题] 建立二元树
时间Fri Dec 11 02:24:50 2009
遇到的问题: (题意请描述清楚)
我要写一个二元树的建立
里面会有一个副程式insert
void BS_tree::Insert(struct node *root,int key)
{
if(root == NULL){
root=(struct node *)malloc(sizeof(struct node));
if(root != NULL){
root -> data = key;
root -> left = NULL;
root -> right = NULL;
}
else{
printf("%d not inserted.No memory available.\n",key);
}
}
else{
if(key < root->data){
Insert(root->left,key);
}
else if(key > root->data){
Insert(root->right,key);
}
else{
printf("dup");
}
}
}
程式跑出来的错误结果:
error C2065: 'malloc' : undeclared identifier
开发平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
VC++
补充说明:
我整个程式中有多次用到上面黄字的宣告
却只有那一行会显示有错误
我不知道为什麽会这样
上来问问看大家
不知道是不是我的程式结构写法有错还是怎样?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.41.112.74
※ 编辑: sakurarain 来自: 114.41.112.74 (12/11 02:25)
※ 编辑: sakurarain 来自: 114.41.112.74 (12/11 02:27)
※ 编辑: sakurarain 来自: 114.41.112.74 (12/11 02:31)
1F:→ sunneo:你需要可以从函式名称反查标头档的字典 12/11 04:08
2F:→ VictorTom:只有那行有错是因为後面一样的错误都因为同样错误省略, 12/11 09:31
3F:→ VictorTom:把这一行注解拿掉, 下一个就会被报error了; 最後推1F:) 12/11 09:32