[問題] 建立二元樹
遇到的問題: (題意請描述清楚)
我要寫一個二元樹的建立
裡面會有一個副程式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)
→
12/11 04:08, , 1F
12/11 04:08, 1F
→
12/11 09:31, , 2F
12/11 09:31, 2F
→
12/11 09:32, , 3F
12/11 09:32, 3F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章