问题描述
- c++编程,,跪求大神解答
-
#includeusing 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 时出错.
解决方案
如果你用的是VC++,最好新建一个控制台项目,不要修改默认程序入口的函数名。然后把你的代码贴进去。(推荐)
或者你可以设置下链接器的程序入口点
参考
http://wenku.baidu.com/link?url=sKPXdV8rkVR-o8obBds0KQ65LU4pBH8MD0wsCrpMeDOzXeTByUVg5HYFfuJu5MhLNbZtcAUS9r-HIGwBK5MokMafUyyj0_KnMJhVdGFTh5e
解决方案二:
代码不全,想帮你看看也表示无力
解决方案三:
http://blog.csdn.net/zhangleo1987/article/details/5718653