我新的代码块的错误。我试图找到一个BST的高度,并使用max()
函数。但是在编译的代码块抛出error.I正在使用Windows machine.I知道手动连接maths.h将解决issue.I知道如何链接math.h中使用gcc手动,但我不知道windows.Basically GCC相当于我想知道除了链接之外,还有其他解决方案吗?如果手动链接是唯一的选择,那么在CodeBlocks的Windows上如何做到这一点。谢谢!我是相当新的代码blocks.I已经花了太多时间在这个错误。可有人指出什么是我在这段代码
未定义引用最多
我敢肯定存在逻辑没有错误的所有import语句是正确的了。但仍然没有输出!下面是代码:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//Definition of Node for Binary search tree
struct BstNode {
int data;
struct BstNode* left;
struct BstNode* right;
};
struct BstNode* GetNewNode(int);
struct BstNode* Insert(struct BstNode*,int);
int findHeight(struct BstNode *);
//struct BstNode* findMin(struct BstNode* root)
// Function to create a new Node in heap
struct BstNode* GetNewNode(int data) {
struct BstNode* newNode = (struct BstNode*)malloc(sizeof(struct BstNode));
newNode->data = data;
newNode->left = newNode->right = NULL;
return newNode;
}
// To insert data in BST, returns address of root node
struct BstNode* Insert(struct BstNode* root,int data) {//pass by value therefore * used and reurn stmt.otherwise pbarg ** no return
if(root == NULL) { // empty tree
root = GetNewNode(data);
}
// if data to be inserted is lesser, insert in left subtree.
else if(data <= root->data) {
root->left = Insert(root->left,data);
}
// else, insert in right subtree.
else {
root->right = Insert(root->right,data);
}
return root;
}
int findHeight(struct BstNode * root){
if(root=NULL){
return -1;
}
else{
return max(findHeight(root->left),findHeight(root->right))+1;
}
};
//BstNode* findMin(BstNode* root)
int main() {
int a,b;
struct BstNode* root = NULL; // Creating an empty tree
/*Code to test the logic*/
root = Insert(root,15);
root = Insert(root,10);
root = Insert(root,20);
root = Insert(root,25);
root = Insert(root,8);
root = Insert(root,12);
findHeight(root);
}
是什么让你的错误?的 – ThunderWiring
可能重复的[C - 未定义参照SQRT(或其他数学函数)](http://stackoverflow.com/questions/5248919/c-undefined-reference-to-sqrt-or-other-mathematical-functions) – aghidini
你在哪里听说过max()函数?有没有这样的事情在'math.h' – jbm