| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 999 人关注过本帖
标题:这个程序错哪了
只看楼主 加入收藏
孤单旋律
Rank: 2
等 级:论坛游民
帖 子:30
专家分:23
注 册:2010-10-22
结帖率:78.57%
收藏
 问题点数:0 回复次数:4 
这个程序错哪了
这是“BiTree.h”头文件
typedef struct Node
{
    DataType data;
    struct Node * leftChild;
    struct Node * rightChild;
}BiTreeNode;
void Initiate(BiTreeNode * * root)
{
    * root=(BiTreeNode * )malloc(sizeof(BiTreeNode));
    ( * root)->leftChild=NULL;
    ( * root)->rightChild=NULL;
}
BiTreeNode * InsertLeftNode(BiTreeNode * curr,DataType x)
{
    BiTreeNode * s, * t;
    if(curr==NULL)return NULL;
    t=curr->leftChild;
    s=(BiTreeNode * )malloc(sizeof(BiTreeNode));
    s->data=x;
    s->leftChild=t;
    s->rightChild=NULL;
    curr->leftChild=s;
    return curr->leftChild;
}
BiTreeNode * InsertRightNode(BiTreeNode * curr,DataType x)
{
    BiTreeNode * s, * t;
    if(curr==NULL)return NULL;
    t=curr->rightChild;
    s=(BiTreeNode * )malloc(sizeof(BiTreeNode));
    s->data=x;
    s->rightChild=t;
    s->leftChild=NULL;
    curr->rightChild=s;
    return curr->rightChild;
}

BiTreeNode  * DeleteLeftTree(BiTreeNode * curr)
{
    if(curr==NULL||curr->leftChild==NULL)return NULL;
    Destroy(&curr->leftChild);
    curr->leftChild=NULL;
    return curr;
}
BiTreeNode * DeleteRightTree(BiTreeNode * curr)
{
    if(curr==NULL||curr->rightChild==NULL)return NULL;
    Destroy(&curr->rightChild);
    curr->rightChild=NULL;
    return curr;
}

这是“BitreeTraverse.h”这是头文件
void PreOrder(BiTreeNode * t,void Visit(DataType item))
{
    if(t!=NULL)
    {
        Visit(t->data);
        PreOrder(t->leftChild,Visit);
        PreOrder(t->rightChild,Visit);
    }
}
void InOrder(BiTreeNode * t,void Visit(DataType item))
{
    if(t!=NULL)
    {
        InOrder(t->leftChild,Visit);
        Visit(t->data);
        InOrder(t->rightChild,Visit);
    }
}
void PostOrder(BiTreeNode * t,void Visit(DataType item))
{
    if(t!=NULL)
    {
        PostOrder(t->leftChild,Visit);
        PostOrder(t->rightChild,Visit);
        Visit(t->data);
    }
}
void Destroy(BiTreeNode * * root)
{
    if(( * root)!=NULL&&( * root)->leftChild!=NULL)
        Destroy(&( * root)->leftChild);
    if(( * root)!=NULL&&( * root)->rightChild!=NULL)
        Destroy(&( * root)->rightChild);
    free( * root);
}

这是源文件
#include<stdlib.h>
#include<stdio.h>
typedef char DataType;
#include"BiTree.h"
#include"BiTreeTraverse.h"
void Visit(DataType item)
{
    printf("%c",item);
}
void PrintBiTree(BiTreeNode * bt,int n)
{
    int i;
    if(bt==NULL)return;
    PrintBiTree(bt->rightChild,n+1);
    for(i=0;i<n;i++)printf("  ");
    if(n>=0)
    {
        printf("---");
        printf("%c\n",bt->data);
    }
    PrintBiTree(bt->leftChild,n+1);
}
void main(void)
{
        BiTreeNode * root, * p, * pp;
        Initiate(&root);
        p=InsertLeftNode(root,'A');
        p=InsertLeftNode(p,'B');
        p=InsertLeftNode(p,'D');
        p=InsertRightNode(p,'G');
        p=InsertRightNode(root->leftChild,'C');
        pp=p;
        InsertLeftNode(p,'E');
        InsertRightNode(pp,'F');
        PrintBiTree(root,0);
        printf("前序遍历:");
        PreOrder(root->leftChild,Visit);
        printf("\n中序遍历:");
        InOrder(root->leftChild,Visit);
        printf("\n后序遍历:");
        PostOrder(root->leftChild,Visit);
        Destroy(&root);
}

编译的时候说
e:\二叉树程序\bitree.h(41) : error C2065: 'Destroy' : undeclared identifier
e:\二叉树程序\bitreetraverse.h(29) : error C2373: 'Destroy' : redefinition; different type modifiers
执行 cl.exe 时出错.
那要怎么改呢?

[ 本帖最后由 孤单旋律 于 2011-4-28 11:32 编辑 ]
搜索更多相关主题的帖子: return 
2011-04-28 09:24
succubus
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:635
专家分:1080
注 册:2007-10-7
收藏
得分:0 
#include"BiTree.h"
#include"BiTreeTraverse.h"
这俩换下位置应该就欧了。。。

[url=http:///view/aDU1]/image/aDU1.gif" border="0" />[/url]
2011-04-28 09:29
孤单旋律
Rank: 2
等 级:论坛游民
帖 子:30
专家分:23
注 册:2010-10-22
收藏
得分:0 
回复 2楼 succubus
我换了一下,可是错的更多!
e:\二叉树程序\bitreetraverse.h(1) : error C2065: 'BiTreeNode' : undeclared identifier
e:\二叉树程序\bitreetraverse.h(1) : error C2065: 't' : undeclared identifier
e:\二叉树程序\bitreetraverse.h(1) : error C2062: type 'void' unexpected
e:\二叉树程序\bitreetraverse.h(2) : error C2143: syntax error : missing ';' before '{'
e:\二叉树程序\bitreetraverse.h(2) : error C2447: missing function header (old-style formal list?)
e:\二叉树程序\bitreetraverse.h(10) : error C2062: type 'void' unexpected
e:\二叉树程序\bitreetraverse.h(11) : error C2143: syntax error : missing ';' before '{'
e:\二叉树程序\bitreetraverse.h(11) : error C2447: missing function header (old-style formal list?)
e:\二叉树程序\bitreetraverse.h(19) : error C2062: type 'void' unexpected
e:\二叉树程序\bitreetraverse.h(20) : error C2143: syntax error : missing ';' before '{'
e:\二叉树程序\bitreetraverse.h(20) : error C2447: missing function header (old-style formal list?)
e:\二叉树程序\bitreetraverse.h(28) : error C2065: 'root' : undeclared identifier
e:\二叉树程序\bitreetraverse.h(28) : error C2100: illegal indirection
e:\二叉树程序\bitreetraverse.h(29) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
e:\二叉树程序\bitree.h(6) : error C2378: 'BiTreeNode' : redefinition; symbol cannot be overloaded with a typedef
e:\二叉树程序\bitree.h(7) : error C2100: illegal indirection
e:\二叉树程序\bitree.h(8) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
e:\二叉树程序\bitree.h(13) : error C2143: syntax error : missing ';' before '*'
e:\二叉树程序\bitree.h(13) : error C2501: 'BiTreeNode' : missing storage-class or type specifiers
e:\二叉树程序\bitree.h(13) : error C2061: syntax error : identifier 'BiTreeNode'
e:\二叉树程序\bitree.h(14) : error C2501: 'InsertLeftNode' : missing storage-class or type specifiers
e:\二叉树程序\bitree.h(15) : error C2065: 's' : undeclared identifier
e:\二叉树程序\bitree.h(15) : error C2100: illegal indirection
e:\二叉树程序\bitree.h(16) : error C2065: 'curr' : undeclared identifier
e:\二叉树程序\bitree.h(17) : error C2227: left of '->leftChild' must point to class/struct/union
e:\二叉树程序\bitree.h(18) : error C2059: syntax error : ')'
e:\二叉树程序\bitree.h(19) : error C2227: left of '->data' must point to class/struct/union
e:\二叉树程序\bitree.h(19) : error C2065: 'x' : undeclared identifier
e:\二叉树程序\bitree.h(20) : error C2227: left of '->leftChild' must point to class/struct/union
e:\二叉树程序\bitree.h(21) : error C2227: left of '->rightChild' must point to class/struct/union
e:\二叉树程序\bitree.h(22) : error C2227: left of '->leftChild' must point to class/struct/union
e:\二叉树程序\bitree.h(23) : error C2227: left of '->leftChild' must point to class/struct/union
e:\二叉树程序\bitree.h(23) : error C2617: 'InsertLeftNode' : inconsistent return statement
        e:\二叉树程序\bitree.h(13) : see declaration of 'InsertLeftNode'
e:\二叉树程序\bitree.h(25) : error C2143: syntax error : missing ';' before '*'
e:\二叉树程序\bitree.h(25) : error C2501: 'BiTreeNode' : missing storage-class or type specifiers
e:\二叉树程序\bitree.h(25) : error C2086: 'BiTreeNode' : redefinition
e:\二叉树程序\bitree.h(25) : error C2061: syntax error : identifier 'BiTreeNode'
e:\二叉树程序\bitree.h(26) : error C2501: 'InsertRightNode' : missing storage-class or type specifiers
e:\二叉树程序\bitree.h(27) : error C2100: illegal indirection
e:\二叉树程序\bitree.h(29) : error C2227: left of '->rightChild' must point to class/struct/union
e:\二叉树程序\bitree.h(30) : error C2059: syntax error : ')'
e:\二叉树程序\bitree.h(31) : error C2227: left of '->data' must point to class/struct/union
e:\二叉树程序\bitree.h(32) : error C2227: left of '->rightChild' must point to class/struct/union
e:\二叉树程序\bitree.h(33) : error C2227: left of '->leftChild' must point to class/struct/union
e:\二叉树程序\bitree.h(34) : error C2227: left of '->rightChild' must point to class/struct/union
e:\二叉树程序\bitree.h(35) : error C2227: left of '->rightChild' must point to class/struct/union
e:\二叉树程序\bitree.h(35) : error C2617: 'InsertRightNode' : inconsistent return statement
        e:\二叉树程序\bitree.h(25) : see declaration of 'InsertRightNode'
e:\二叉树程序\bitree.h(38) : error C2143: syntax error : missing ';' before '*'
e:\二叉树程序\bitree.h(38) : error C2501: 'BiTreeNode' : missing storage-class or type specifiers
e:\二叉树程序\bitree.h(38) : error C2086: 'BiTreeNode' : redefinition
e:\二叉树程序\bitree.h(38) : error C2061: syntax error : identifier 'BiTreeNode'
e:\二叉树程序\bitree.h(39) : error C2501: 'DeleteLeftTree' : missing storage-class or type specifiers
e:\二叉树程序\bitree.h(40) : error C2227: left of '->leftChild' must point to class/struct/union
e:\二叉树程序\bitree.h(41) : error C2065: 'Destroy' : undeclared identifier
e:\二叉树程序\bitree.h(41) : error C2227: left of '->leftChild' must point to class/struct/union
e:\二叉树程序\bitree.h(42) : error C2227: left of '->leftChild' must point to class/struct/union
e:\二叉树程序\bitree.h(45) : error C2143: syntax error : missing ';' before '*'
e:\二叉树程序\bitree.h(45) : error C2501: 'BiTreeNode' : missing storage-class or type specifiers
e:\二叉树程序\bitree.h(45) : error C2086: 'BiTreeNode' : redefinition
e:\二叉树程序\bitree.h(45) : error C2061: syntax error : identifier 'BiTreeNode'
e:\二叉树程序\bitree.h(46) : error C2501: 'DeleteRightTree' : missing storage-class or type specifiers
e:\二叉树程序\bitree.h(47) : error C2227: left of '->rightChild' must point to class/struct/union
e:\二叉树程序\bitree.h(48) : error C2227: left of '->rightChild' must point to class/struct/union
e:\二叉树程序\bitree.h(49) : error C2227: left of '->rightChild' must point to class/struct/union
E:\二叉树程序\bitree.cpp(11) : error C2065: 'bt' : undeclared identifier
E:\二叉树程序\bitree.cpp(11) : error C2062: type 'int' unexpected
E:\二叉树程序\bitree.cpp(12) : error C2143: syntax error : missing ';' before '{'
E:\二叉树程序\bitree.cpp(12) : error C2447: missing function header (old-style formal list?)
E:\二叉树程序\bitree.cpp(26) : error C2065: 'p' : undeclared identifier
E:\二叉树程序\bitree.cpp(26) : error C2100: illegal indirection
E:\二叉树程序\bitree.cpp(26) : error C2065: 'pp' : undeclared identifier
E:\二叉树程序\bitree.cpp(26) : error C2100: illegal indirection
E:\二叉树程序\bitree.cpp(27) : error C2065: 'Initiate' : undeclared identifier
E:\二叉树程序\bitree.cpp(32) : error C2227: left of '->leftChild' must point to class/struct/union
E:\二叉树程序\bitree.cpp(32) : error C2660: 'InsertRightNode' : function does not take 2 parameters
E:\二叉树程序\bitree.cpp(36) : error C2065: 'PrintBiTree' : undeclared identifier
E:\二叉树程序\bitree.cpp(38) : error C2065: 'PreOrder' : undeclared identifier
E:\二叉树程序\bitree.cpp(38) : error C2227: left of '->leftChild' must point to class/struct/union
E:\二叉树程序\bitree.cpp(40) : error C2065: 'InOrder' : undeclared identifier
E:\二叉树程序\bitree.cpp(40) : error C2227: left of '->leftChild' must point to class/struct/union
E:\二叉树程序\bitree.cpp(42) : error C2065: 'PostOrder' : undeclared identifier
E:\二叉树程序\bitree.cpp(42) : error C2227: left of '->leftChild' must point to class/struct/union
执行 cl.exe 时出错.
2011-04-28 09:59
succubus
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:635
专家分:1080
注 册:2007-10-7
收藏
得分:0 

刚才没细看
那就保持这俩儿的顺序
#include"BiTree.h"
#include"BiTreeTraverse.h"
然后直接把BitreeTraverse.h里的Destroy函数在bitree.h里声明一下就行了

[url=http:///view/aDU1]/image/aDU1.gif" border="0" />[/url]
2011-04-28 10:06
孤单旋律
Rank: 2
等 级:论坛游民
帖 子:30
专家分:23
注 册:2010-10-22
收藏
得分:0 
回复 4楼 succubus
朋友,能不能帮我写一下那个函数,我不太明白!谢了
2011-04-28 10:21
快速回复:这个程序错哪了
数据加载中...
 
   



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

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