c++ - 错误 LNK2019 未解析的外部符号 _main
问题描述
我在编译时遇到了代码中的错误,我对如何继续感到有些困惑。我认为我没有使用最新版本的 Visual Studio。我对 C++ 并不完全陌生,也不是经验丰富的人——但我确信我的函数在正确的位置并且int main()
很好。所以我只是有点困惑。如果有人能给我第二双眼睛,并解释我的错误/错误行为,以及我如何才能做得更好,我将不胜感激!
#include <iostream>
#include <queue>
#include <fstream>
#include "binaryTreeType.h"
#include "binarySearchTree.h"
using namespace std;
struct node {
int data;
node* left;
node* right;
};
node* newNode(int item) {
node* temp = new node;
temp->data = item;
temp->left = NULL;
temp->right = NULL;
return temp;
}
//Inorder traversal of tree
void inorder(node* root) {
if (root != NULL) {
inorder(root->left);
printf("%d ", root->data);
inorder(root->right);
}
}
//calculate height of tree
int height(node* root) {
if (root == NULL)
return 0;
else
{
int l = height(root->left);
int r = height(root->right);
return max(l, r) + 1;
}
}
node* binarySearchTree(node* head, int data) {
if (head == NULL) return newNode(data);
if (data < head->data)
head->left = binarySearchTree(head->left, data);
else if (data > head->data)
head->right = binarySearchTree(head->right, data);
return head;
}
//caluclate single parents of Binary Search Tree
int singleParent(node* root) {
queue<node*> qp;
int ans = 0;
if (root == NULL) {
return 0;
}
qp.push(root);
while (!qp.empty()) {
node* f = qp.front();
qp.pop();
if ((f->left != NULL && f->right == NULL) || (f->right != NULL && f->left == NULL)) {
ans++;
}
if (f->left != NULL) {
qp.push(f->left);
}
if (f->right != NULL) {
qp.push(f->right);
}
}
return ans;
}
int main() {
node* root = NULL;
cout << "Please enter elements ending with -1:" << endl;
int x;
cin >> x;
while (x != -1) {
root = binarySearchTree(root, x);
cin >> x;
}
//display
cout << "The tree elements within Inorder are: " << inorder(root) << endl;
cout << "Tree height is: " << height(root) << endl;
cout << "Number of single parents: " << singleParent(root) << endl;
return 0;
}
解决方案
推荐阅读
- html - 带有columns-*的css flex项目拉伸太多
- mysql - 创建多列索引,包括相关表中的列
- swift - 无法从 ORSSerialPort 接收数据
- javascript - 如何存储变量的原始形式?
- javascript - 如何捕获并报告“由于其 MIME 类型(...)和严格的 MIME 类型(...)而拒绝执行脚本”问题?
- ios - UICollectionView:旋转设备时保持单元格可见
- spring-boot - Spring Boot 和 keycloak 授权
- django - Django - 使用字符串 pk 按作者过滤帖子?
- flutter - TabBarView 中的 FutureBuilder 未正确更新
- mysql - 我收到此错误“错误 #1241 - 操作数应在 Mysql 中包含 1 列”,请解决此问题