| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 373 人关注过本帖
标题:建的这个数不能实现啊哪位高手给我点建议直接建个树而不是自己输入元素让人 ...
只看楼主 加入收藏
人生啊
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-11-12
结帖率:0
收藏
已结贴  问题点数:10 回复次数:2 
建的这个数不能实现啊哪位高手给我点建议直接建个树而不是自己输入元素让人系统自己建
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 20
typedef struct BiTnode{
 char data;
 struct BiTnode *lchild,*rchild;
}BiTnode,*BiTree;
int i=0;

void display(BiTree t)
{
    BiTree stack[MAXSIZE],p;

    int top=-1;
    if(t)
    {
        p=t;

    while(top>-1||p)
            
    {   
        while(p)
        {
            stack[++top]=p;
            p=p->lchild;
        }
        
   
     if(top>-1)
     {
        p=stack[top--];
        printf("%c ",p->data);
        p=p->rchild;
     }
    }
    printf("\n");
    }
}

void play(BiTree t)

{

 if(t)

 {

  play(t->lchild);

  printf("%c ",t->data);

  play(t->rchild);

 }
}

void asplay(BiTree t)

{

 if(t)

 {

  printf("%c ",t->data);

  asplay(t->lchild);

  asplay(t->rchild);

 }
}
BiTree Create(BiTree t)
{
    char s[]="abc  de f  g    ";
    char ch;
    ch=s[i++];
    if(ch==' ')
    {
        t=NULL;
    }
    else
    {
        if(!(t=(BiTree)malloc(sizeof(BiTree))))
        {
        printf("The malloc is fail!");
        exit(0);
        }
        else
        {
        t->data=ch;
        t->lchild=Create(t->lchild);
        t->rchild=Create(t->rchild);
        }
    }
    return t;
}
int main()
{
    BiTree t;
   
    t=Create(t);
    display(t);
    play(t);
    printf("\n");
    asplay(t);
    return 0;
}
搜索更多相关主题的帖子: display display top top include include 元素 元素 
2012-11-12 21:31
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:10 
给我发汇编版来 谁能看到啊 发帖为嘛不看版块

QQ上问的不会是这位朋友罢 问我数据结构 我活20多年没学过一天的数据结构。。
2012-11-12 21:32
人生啊
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-11-12
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 20
typedef struct BiTnode{
 char data;
 struct BiTnode *lchild,*rchild;
}BiTnode,*BiTree;
int i=0;


void play(BiTree t)

{

 if(t)

 {

  play(t->lchild);

  printf("%c ",t->data);

  play(t->rchild);

 }
}

void asplay(BiTree t)

{

 if(t)

 {

  printf("%c ",t->data);

  asplay(t->lchild);

  asplay(t->rchild);

 }
}
BiTree Create(BiTree t)
{
    char s[]="abc  de f  g    ";
    char ch;
    ch=s[i++];
    if(ch==' ')                          能不能在这里面建个树呢
    {
        t=NULL;
    }
    else
    {
        if(!(t=(BiTree)malloc(sizeof(BiTree))))
        {
        printf("The malloc is fail!");
        exit(0);
        }
        else
        {
        t->data=ch;
        t->lchild=Create(t->lchild);
        t->rchild=Create(t->rchild);
        }
    }
    return t;
}
int main()
{
    BiTree t;
   
    t=Create(t);
    display(t);
    play(t);
    printf("\n");
    asplay(t);
    return 0;
}
2012-11-12 21:34
快速回复:建的这个数不能实现啊哪位高手给我点建议直接建个树而不是自己输入元素 ...
数据加载中...
 
   



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

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