标题:有关栈与树的问题,郁闷很久了~大家都来看看啊谢了~
只看楼主
wycwyc
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2008-10-18
 问题点数:0 回复次数:0 
有关栈与树的问题,郁闷很久了~大家都来看看啊谢了~
就是用栈储存树,再调用函数求树的根节点

#include<stdio.h>
#include"malloc.h"

typedef struct node
{
    char data;
    struct node *lchild;
    struct node *rchild;
}shu;

typedef struct
{ shu * qu[100];
  int top;
} SeqStack;

SeqStack* make()
{
 SeqStack *w;
 w=(SeqStack*)malloc(sizeof(SeqStack));
 w->top=1;
 return w;
}

SeqStack * past()
{
    char ch;
    SeqStack *w;
    int j=0,n=0;
    shu *root=NULL,*s=NULL;
    ch=getchar();
    while(ch!='\n')
    {
        if(ch=='@')w->qu[w->top]=NULL;
        else if(w->top>1&&w->qu[w->top/2]==NULL)//我调试时程序走到这里就走不下去了,提示undandled exceptionin wycwyc.exe:OxCOOOOOO5:Violation 是说的什么意思 帮忙解释下谢了//        {ch=getchar();continue;}
        else
        {
            s=(shu*)malloc(sizeof(shu));
            s->data=ch;s->lchild=NULL;s->rchild=NULL;
            w->qu[w->top]=s;
            if(w->top==1)root=s;
            else if(w->top%2==0) w->qu[w->top/2]->lchild=s;
            else w->qu[w->top/2]->rchild=s;
            n++;
        }printf("iiii");
        w->top++;
        ch=getchar();
    }printf("%d",w->qu[w->top]);
    return (w);
}

main()
{
    SeqStack *W;
    W=make();
    W=past();
    printf("%d",W->qu[W->top]);
}
搜索更多相关主题的帖子: include return while 
2008-11-21 16:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-245594-1-1.html




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

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