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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器