| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 920 人关注过本帖
标题:二叉树
只看楼主 加入收藏
heliujin
Rank: 2
等 级:论坛游民
帖 子:249
专家分:14
注 册:2006-3-14
结帖率:100%
收藏
 问题点数:0 回复次数:1 
二叉树

二叉树的排序 和中序遍历
#include<iostream.h>
#include<iomanip.h>
int list=1;
struct sport
{
char num[4];
double grade;
};
struct tree
{
soprt *spt;
tree *left,*right;
};
class Btree
{
tree *root;
public:
Btree(){root=NULL;}
void creat_btree(soprt *);
void display()
{
cout<<"mingci<<" "<<"bianhao"<<" "<<"chengji"<<endl;
inorder(root);
cout<<endl;
}
void inorder(tree *);
};
void Btree::creat_btree(sport *x)
{
tree *newnode=new tree;
newnode->spt=x;
newnode->left=newnode->right=NULL;
if(root==NULL)
root=newnode;
else
{
tree *back,*current;
current=root;
while(current!=NULL)
{
back=current;
if(current->spt->grade>x_>grade)
current=current->left;
else
current=current->right;
}
if(back->spt->grade>x->grade)
back->left=newnode;
else
back->right=newnode;
}
}
void Btree::inorder(tree *tmp)
{
if(tmp!=NULL)
{
inorder(emp->left);
cout<<setw(4)<<list<<setw(6)<<tmp->spt->num<<setw(8)<<tmp->spt->grade<<endl;
list=list+1;
inorder(tmp->right);
}
}
void main()
{
Btree A;
sport a[12]={{"001",13.6},{"002",14,8},{"010",12.0},{"011",12.7},{"023",15.6},{"025",13.4},{"031",14.9},{"036",12.6},{"037",13.4},{"102",12.5},{"325",15.3},{"438",12.7}};
sport *pa[12]={&a[0],&a[1],&a[2],&a[3],&[4],&a[5],&a[6],&a[7],&a[8],&a[9],&a[10],&a[11],&a[12]};
cout<<"creat the order erchashu jiedian shunxv:"<<endl;
for(int i=0;i<12;i++)
{
cout<<pa[i]->num<<" "<<pa[i]->grade<<endl;
A.creat_btree(pa[i]);
}
cout<<endl<<"zhongxvbianlijieguo:"<<endl;
cout<<endl;
A.display();
}

错误显示如下:
--------------------Configuration: df - Win32 Debug--------------------
Compiling...
书上的二叉树.cpp
F:\我的C++程序\书上的二叉树.cpp(11) : error C2143: syntax error : missing ';' before '*'
F:\我的C++程序\书上的二叉树.cpp(11) : error C2501: 'soprt' : missing storage-class or type specifiers
F:\我的C++程序\书上的二叉树.cpp(11) : error C2501: 'spt' : missing storage-class or type specifiers
F:\我的C++程序\书上的二叉树.cpp(19) : error C2061: syntax error : identifier 'soprt'
F:\我的C++程序\书上的二叉树.cpp(22) : error C2001: newline in constant
F:\我的C++程序\书上的二叉树.cpp(29) : error C2511: 'creat_btree' : overloaded member function 'void (struct sport *)' not found in 'Btree'
F:\我的C++程序\书上的二叉树.cpp(15) : see declaration of 'Btree'
F:\我的C++程序\书上的二叉树.cpp(57) : error C2065: 'emp' : undeclared identifier
F:\我的C++程序\书上的二叉树.cpp(57) : error C2227: left of '->left' must point to class/struct/union
F:\我的C++程序\书上的二叉树.cpp(58) : error C2039: 'spt' : is not a member of 'tree'
F:\我的C++程序\书上的二叉树.cpp(10) : see declaration of 'tree'
F:\我的C++程序\书上的二叉树.cpp(58) : error C2227: left of '->num' must point to class/struct/union
F:\我的C++程序\书上的二叉树.cpp(58) : error C2039: 'spt' : is not a member of 'tree'
F:\我的C++程序\书上的二叉树.cpp(10) : see declaration of 'tree'
F:\我的C++程序\书上的二叉树.cpp(58) : error C2227: left of '->grade' must point to class/struct/union
F:\我的C++程序\书上的二叉树.cpp(66) : error C2078: too many initializers
F:\我的C++程序\书上的二叉树.cpp(67) : error C2059: syntax error : '['
F:\我的C++程序\书上的二叉树.cpp(68) : error C2143: syntax error : missing ';' before '<<'
F:\我的C++程序\书上的二叉树.cpp(68) : error C2501: 'cout' : missing storage-class or type specifiers
F:\我的C++程序\书上的二叉树.cpp(68) : error C2371: 'cout' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\ostream.h(139) : see declaration of 'cout'
F:\我的C++程序\书上的二叉树.cpp(68) : error C2143: syntax error : missing ';' before '<<'
F:\我的C++程序\书上的二叉树.cpp(69) : error C2143: syntax error : missing ';' before 'for'
F:\我的C++程序\书上的二叉树.cpp(69) : error C2143: syntax error : missing ')' before ';'
F:\我的C++程序\书上的二叉树.cpp(69) : error C2143: syntax error : missing ';' before '<'
F:\我的C++程序\书上的二叉树.cpp(69) : error C2501: 'i' : missing storage-class or type specifiers
F:\我的C++程序\书上的二叉树.cpp(69) : error C2143: syntax error : missing ';' before '<'
F:\我的C++程序\书上的二叉树.cpp(69) : error C2143: syntax error : missing ';' before '++'
F:\我的C++程序\书上的二叉树.cpp(69) : error C2501: 'i' : missing storage-class or type specifiers
F:\我的C++程序\书上的二叉树.cpp(69) : error C2086: 'i' : redefinition
F:\我的C++程序\书上的二叉树.cpp(69) : error C2143: syntax error : missing ';' before '++'
F:\我的C++程序\书上的二叉树.cpp(69) : error C2059: syntax error : ')'
F:\我的C++程序\书上的二叉树.cpp(70) : error C2143: syntax error : missing ';' before '{'
F:\我的C++程序\书上的二叉树.cpp(70) : error C2447: missing function header (old-style formal list?)
F:\我的C++程序\书上的二叉树.cpp(74) : error C2143: syntax error : missing ';' before '<<'
F:\我的C++程序\书上的二叉树.cpp(74) : error C2501: 'cout' : missing storage-class or type specifiers
F:\我的C++程序\书上的二叉树.cpp(74) : error C2371: 'cout' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\ostream.h(139) : see declaration of 'cout'
F:\我的C++程序\书上的二叉树.cpp(74) : error C2143: syntax error : missing ';' before '<<'
F:\我的C++程序\书上的二叉树.cpp(75) : error C2143: syntax error : missing ';' before '<<'
F:\我的C++程序\书上的二叉树.cpp(75) : error C2501: 'cout' : missing storage-class or type specifiers
F:\我的C++程序\书上的二叉树.cpp(75) : error C2371: 'cout' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\ostream.h(139) : see declaration of 'cout'
F:\我的C++程序\书上的二叉树.cpp(75) : error C2143: syntax error : missing ';' before '<<'
F:\我的C++程序\书上的二叉树.cpp(76) : error C2143: syntax error : missing ';' before '.'
F:\我的C++程序\书上的二叉树.cpp(76) : error C2501: 'A' : missing storage-class or type specifiers
F:\我的C++程序\书上的二叉树.cpp(76) : error C2143: syntax error : missing ';' before '.'
F:\我的C++程序\书上的二叉树.cpp(77) : error C2143: syntax error : missing ';' before '}'
F:\我的C++程序\书上的二叉树.cpp(77) : error C2143: syntax error : missing ';' before '}'
F:\我的C++程序\书上的二叉树.cpp(77) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.

df.exe - 44 error(s), 0 warning(s) 谢谢大家了

搜索更多相关主题的帖子: 二叉树 
2006-04-21 21:25
tufeiax
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-3-25
收藏
得分:0 
看到你编译的错误数量,我已经没有看程序的想法了......
2013-04-02 17:24
快速回复:二叉树
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050337 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved