| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 615 人关注过本帖
标题:大哥们我求助!!!!!
只看楼主 加入收藏
zhongle66
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-11-10
收藏
 问题点数:0 回复次数:1 
大哥们我求助!!!!!



这个程序应该怎么改啊

好象是需要建个指向字符型的指针!





#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include "stack.h"
//二叉链表的定义
typedef char Telemtype;
typedef struct bitnode
{
Telemtype data;

struct bitnode *lchild,*rchild;
}bitnode,*bitree,*in;

//栈的操作,栈中元素类型为bitree


//建立二叉树
void createbitree(bitree T)
{
Telemtype ch;
scanf("%c",&ch);
if(ch==' ')
T=NULL;
else
{
T=(bitree)malloc(sizeof(bitnode));
T->data=ch;
createbitree(T->lchild);
createbitree(T->rchild);
}
}
//求二叉树的叶子个数
int leaf(bitree T)
{
int n;
if(!T)
n=0;
else
if(!T->lchild&&!T->rchild) n=1;
else
n=leaf(T->lchild)+leaf(T->rchild);
return(n);
}
//先序遍历
void xianxu(bitree T)
{
bitree p;
stack s;
initstack(s);
if(T)
p=T;
push(s,T);
while(!stackempty(s))
{ pop(s,p);
printf("%c",p->data);
if(p->rchild)push(s,p->rchild);
if(p->lchild)push(s,p->lchild);
}

}






#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef char selemtype;
//链栈的定义
typedef struct node
{
selemtype data;
struct node *next;

}node;
typedef struct
{
node *top;

}stack;
#define overflow -2
#define TRUE 1
#define FALSE 0
typedef char status;
void initstack(stack &s)
{
s.top=(node *)malloc(sizeof(node));
if(!s.top) exit(overflow);
s.top->next=NULL;
}
status stackempty(stack s)
{
if(s.top->next==NULL)
return(TRUE);
else
return(FALSE);
}
void push(stack &s,char e)
{
node *p;
p=(node *)malloc(sizeof(node));
if(!p)
return;
p->data=e;
p->next=s.top->next;
s.top->next=p;
}
void pop(stack &s,selemtype &e)
{
node *p;
if(stackempty(s))
return;
else
{
p=s.top->next;
e=p->data;
s.top->next=p->next;
free(p);
}
}



//主函数部分
#include "1.h"
#include "stack.h"
#include "math.h"
#include "stdio.h"
void main()
{
bitree root;
int select;
printf("建立二叉数\n");
crearebitree(root);
do
{
printf("1 先序 2 叶子数目 3 退出\n");
scanf("%d",%select);
switch(select)
{
case 1:
printf("先序遍历\n");
xianshu(root);
break;
case 2:
printf("二叉树中叶子数目\n");
break;
case 3:
break;
default:
printf("输入选项错误\n");
}

}while(select);
}

搜索更多相关主题的帖子: include 二叉树 元素 
2005-11-10 22:21
zhongle66
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-11-10
收藏
得分:0 
44

那个 *in 我已经删除了
及待解决我程序中的问题

请多指教

大侠们帮忙啊

2005-11-10 22:23
快速回复:大哥们我求助!!!!!
数据加载中...
 
   



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

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