相关讨论
谁有二叉树的递归和非递归的前后中序遍历,帮忙发上来一下。C实现。
在我的应用编程中从来没有用到过二叉树,最多用到过一些线性链表,不知道各位在从业的经历中用过没有?
在 严老师的 算法9.12中
LeftBalance函数
switch(rd->bf) 我没看懂,应该只有 case EH 一种情况,怎么会有
LH,RH 的case,插入的就是一个节点,不会是一棵树吧.
另外他的处理方式也看不明白,
case LH: T->bf=RH; ???
请教一下大家,谢谢啊,
自己写了个层序遍历二叉树的一个小程序,编译通过,运行到红色部分出现段错误,不知道怎么回事,大家帮我看看吧呵呵
#include
#include
struct _b_tree_node {
int data;
struct _b_tree_node *lchild,*rchild;
}b_tree_node;
typedef struct _b_tree_node *Btree;
//create binary trees
Btree create_b_tree(Btree t) {
Btree node;
int d;
printf("input ...
请教各位高手...
//输出从根到指定值间的所有元素
#include
#include
using namespace std;
template class Btree;
template
class BtreeNode
{
private:
Telem data;
BtreeNode* lchild;
BtreeNode* rchild;
friend class Btree;
public:
...
SICP 的第二章陈述了这样的观点:数据可以看成一组建构函数和选择函数。较新一些的函式语言对此有内建的支持,即把建构函数和选择函数标准化了。以 ML 为例,它的 datatype 可以构建新的类型,支持多态和递归。在 scheme,选择函数通常要作一系列的判断后,才能从数据中挑出所需部分。ML为此提供了模式匹配。从本质上看,模式匹配跟分情处理没有区别。但模式匹配显然更清晰,用起来也轻松得多。
这是二叉树创建并中序遍历的程序可是一直有错
#include
#define struct_sizes 20
#define adds 10
typedef struct bitnode
{
int data;
struct bitnode *lchild,*rchild;
}bitnode,*bitree;
typedef struct
{ bitree *base;
bitree *top;
int stacksize;
}sqstack;
int initstack(sqstack *S)
{
S->base=(bitree*)malloc(struct_sizes*sizeof(bitree));
printf("chuan jian cheng gong");
if(!S->base)return ...
这是一个创建二叉树并中序遍历的程序,可是却是错的,
#include
#include
#include
typedef int Status;
typedef int TElemType;
typedef struct btnode
{ TElemType data;
struct btnode *lchild,*rchild;
}btnode,*bitree;
void Create(bitree T)
{
int ch;
scanf("%d",&ch);
if(ch==0)
T=NULL;
else{
T=(bitree)malloc(sizeof(btnode));
T->data=ch;
Creat...
现在在做一个多分类程序,需要保存二叉树
要求将内存中的二叉树保存成文本形式,文本具有可读性,可编辑性。并且从文本恢复的二叉树与原二叉树相同
目前我想到的方式是保存父子关系,比如:
ABC
BED
CFG
EHI
...
哪位高人给个更好的方案阿
by
reiase
-
C/C++
-
2008-04-01 18:15:06 阅读(2790) 回复(13)
[code]def isnum(a):
if type(a)==type(1):
return True
return False
def first_root(a):
print a[1],'-',
if isnum(a[0]):
print a[0],'-',
else:
first_root(a[0])
if isnum(a[2]):
print a[2],'-',
else:
first_root(a[2])
def middle_root(a):
if isnum(a[0]):
print a[0],'-',
else:
middle_root(a[0])
print a[1],'-',
...