[問題] 建立二元樹

看板C_and_CPP (C/C++)作者 (茫然不知所以)時間16年前 (2009/12/11 02:24), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
遇到的問題: (題意請描述清楚) 我要寫一個二元樹的建立 裡面會有一個副程式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
把這一行註解拿掉, 下一個就會被報error了; 最後推1F:)
12/11 09:32, 3F
文章代碼(AID): #1B8Jprwu (C_and_CPP)
文章代碼(AID): #1B8Jprwu (C_and_CPP)