Wangchao20134490 2014-12-20 01:42 采纳率: 0%
浏览 1872

c++编程,,跪求大神解答

#include

using namespace std;

template

struct BiNode

{
BiNode *lchild;
datatype data;
BiNode *rchild;

};

template

struct element

{

BiNode *ptr;
int flag;

};

BiNode *first,*bt,*q,*temp,stack[20],queue[20];

element s[20];

int count=0;

template

class BiTree

{

void creat(BiNode<datatype> *bt) 

{
char ch;
cin>>ch;
if(ch=='#') bt=NULL;
else
{
bt==new BiNode;
bt->data=ch;
creat(bt->lchild);
creat(bt->rchild);
}
}
void preorder(BiNode *bt)
{
int top=-1;
while(bt!=NULL || top!=-1)
{
while(bt!=NULL)
{
cout<data;
stack[++top]=*bt;
bt=bt->lchild;
}
if(top!=-1)
{
bt=&stack[top--];
bt=bt->rchild;
}
}
}

void inorder(BiNode bt)
{
int top=-1;
while(bt!=NULL || top!=-1)
{
while(bt!=NULL)
{
stack[++top]=*bt;
bt=bt->lchild; }
if(top!=-1)
{
bt=&stack[top--];
cout<data;
bt=bt->rchild;
}
}
}

void postorder(BiNode *bt)
{ int top=-1;
while(bt!=NULL || top!=-1)
{
while(bt!=NULL)
{ top++;
s[top].ptr=bt;
s[top].flag=1;
bt=bt->lchild;
}
while(top!=-1 && s[top].flag==2)
{ bt=s[top--].ptr;
cout<data;
if(top==-1);
bt=NULL;
}
if(top!=-1)
{
s[top].flag=2;
root=s[top].ptr->rchild;
}
}
}
void levelorder(BiNode *bt)
{
int front,rear;
front=rear=0;
if(bt==NULL) return;
queue[++rear]=*bt;
while(front!=rear)
{ q=&queue[++front];
cout<data;
if(q->lchild!=NULL) queue[++rear]=
(q->lchild);
if(q->rchild!=NULL) queue[++rear]=*(q->rchild);
}
}

void dgpreorder(BiNode *bt)
{
if(bt==NULL) return;
else
{
cout<data;
dgpreorder(bt->lchild);
dgpreorder(bt->rchild);
}
}
void dginorder(BiNode *bt)
{if(bt==NULL) return;
else
{
dginorder(bt->lchild);
cout<data;
dginorder(bt->rchild);
}

}
void dgpostorder(BiNode *bt)
{
if(bt==NULL) return;
else
{
dgpostorder(bt->lchild);
dgpostorder(bt->rchild);
cout<data;
}

}
void countleaf(BiNode *bt,int &count)

{
if(bt!=NULL)
{
if(bt->lchild==NULL && bt->rchild==NULL)
count++;
countleaf(bt->lchild,count);
countleaf(bt->rchild,count);
}

}

void main()

{

BiTree my;

cout<<"请依次输入拓展二叉树的前序遍历序列:"<<endl;
my.creat(bt);
first=bt;

cout<<"以下为非递归算法的各种遍历序列:"<<endl;
cout<<"二叉树的前序遍历序列为:"<<endl;
my.preorder(first);

cout<<"二叉树的中序遍历序列为:"endl;
my.inorder(first);

cout<<"二叉树的后序遍历序列为:"<<endl;
my.postorder(first);

cout<<"二叉树的层序遍历序列为:"<endl;
my.levelorder(first);

cout<<"以下为递归算法的各种遍历序列:"<<endl;
cout<<"二叉树的前序遍历序列为:"<endl;
my.dgpreorder(first);

cout<<"二叉树的中序遍历序列为:"<<endl;
my.dginorder(first);

cout<<"二叉树的后序遍历序列为:"<<endl;
my.dgpostorder(first);
my.countleaf(first,count);

cout<<"叶子结点的个数:"<<count<<endl;

cout<<endl;

}
};

总是出现这两个错误,请问要怎么解决??
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/bitree.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

  • 写回答

3条回答 默认 最新

  • threenewbee 2014-12-20 01:50
    关注

    如果你用的是VC++,最好新建一个控制台项目,不要修改默认程序入口的函数名。然后把你的代码贴进去。(推荐)

    或者你可以设置下链接器的程序入口点
    参考
    http://wenku.baidu.com/link?url=sKPXdV8rkVR-o8obBds0KQ65LU4pBH8MD0wsCrpMeDOzXeTByUVg5HYFfuJu5MhLNbZtcAUS9r-HIGwBK5MokMafUyyj0_KnMJhVdGFTh5e

    评论

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题