注册 登录
编程论坛 数据结构与算法

大家看看噢,这个是怎么的错误,老是运行不对!!

tanghf1014 发布于 2010-11-10 20:49, 735 次点击
#incldue<stdafx.h>
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef char DataType;

struct TreeNode{
    DataType data;
    struct TreeNode *lchild,*rchild;
};
typedef TreeNoDE *BinTree;
BinTree CreateBinTree(){
    char ch;
    printf("shuruzhifu\n");
    scanf("%c",&ch);
    TreeNode* pNode;
    if(ch=='0'){
        pNode=Null;
    }
    else{
        pNode=(TreeNode*)malloc(sizeof(TreeNode));
        if(pNode==NULL){
            printf("shengqingkongjianshibai");
            exit(0);
        }
        pNode->data=ch;
        pNode->lchild=CreateBinTree();
        pNode->rchild=CreateBinTree();
    }
    return pNode;
}

void PerOrder(BinTree pRoot){/*前序*/
    if(pRoot){
        pirntf("%c\n",pRoot->data);
        PerOrder(pRoot->lchild);
        PreOrder(pRoot->rchild)
    }
}
void InOrder(BinTree pRoot){/*中序*/
    if(pRoot){
        InOrder(pRoot->lchild);
        printf("%c\n",pRoot->data);
        InOrder(pRoot->rchild);
    }
}
void PostOrder(BinTree pRoot){/*后序*/
    if(pRoot){
        PostOrder(pRoot->lchild);
        PostOrder(pRoot->rchild);
        printf("%c\n",pRoot->data);
    }
}
void StackPreOrder(BinTree pRoot){
    TreeNode* stack[200];
    int top=-1;
    BinTree p=pRoot;
    stack[++top]=p;
    while(p!=NULL || top!=-1){
        if(p){
            printf("%c",p->data);
            stack[++top]=p->lchild;
        }
        else{
            p=stack[top--];
            p=p->rchild;
        }
    }
}
int main(int argc,char* argv[])
{
    BinTree pRoot;
    CreateBinTree(&pRoot);
    printf("前序遍历:");
    PreOrder(pRoot);
    printf("\n");
    printf("中序遍历:");
    InOrder(pRoot);
    printf("\n");
    printf("后序遍历:");
    PostOrder(pRoot);
    printf("\n");
    printf("\n");
    return 0;
}


//fatal error C1021: invalid preprocessor command 'incldue'
执行 cl.exe 时出错.
3 回复
#2
sambean2010-11-11 19:13
invalid  非法的
incldue
是 include 不是 incldue
#3
m21wo2010-11-11 19:18
程序代码:

#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef char DataType;

struct TreeNode{
    DataType data;
    struct TreeNode *lchild,*rchild;
};// 类型说明
typedef TreeNode* BinTree;
BinTree CreateBinTree(){
    char ch;
    printf("shuruzhifu\n");
    scanf("%c",&ch);
    TreeNode* pNode;
    if(ch=='0'){
        pNode=NULL;  //  马虎
    }
    else{
        pNode=(TreeNode*)malloc(sizeof(TreeNode));
        if(pNode==NULL){
            printf("shengqingkongjianshibai");
            exit(0);
        }
        pNode->data=ch;
        pNode->lchild=CreateBinTree();
        pNode->rchild=CreateBinTree();
    }
    return pNode;
}

void PreOrder(BinTree pRoot){/*前序*/
    if(pRoot){
        printf("%c\n",pRoot->data);  //马虎
        PreOrder(pRoot->lchild);
        PreOrder(pRoot->rchild);  // 马虎
    }
}
void InOrder(BinTree pRoot){/*中序*/
    if(pRoot){
        InOrder(pRoot->lchild);
        printf("%c\n",pRoot->data);
        InOrder(pRoot->rchild);
    }
}
void PostOrder(BinTree pRoot){/*后序*/
    if(pRoot){
        PostOrder(pRoot->lchild);
        PostOrder(pRoot->rchild);
        printf("%c\n",pRoot->data);
    }
}
void StackPreOrder(BinTree pRoot){
    TreeNode* stack[200];
    int top=-1;
    BinTree p=pRoot;
    stack[++top]=p;
    while(p!=NULL || top!=-1){
        if(p){
            printf("%c",p->data);
            stack[++top]=p->lchild;
        }
        else{
            p=stack[top--];
            p=p->rchild;
        }
    }
}
int main(int argc,char* argv[])
{
    BinTree pRoot;
    pRoot=CreateBinTree(); // 这么写
    printf("前序遍历:");
    PreOrder(pRoot);
    printf("\n");
    printf("中序遍历:");
    InOrder(pRoot);
    printf("\n");
    printf("后序遍历:");
    PostOrder(pRoot);
    printf("\n");
    printf("\n");
    return 0;
}


#4
tanghf10142010-11-11 22:53
看来是大马虎了...
1