急求帮助,这个代码的递归有有关问题,要如何改
急急急,求帮助,这个代码的递归有问题,要怎么改
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define MAX_TREE_SIZE 100
//树的双亲表示结点结构定义
typedef struct
{
int data;
int parent;
}PTNode;
//双亲表示法树
typedef struct
{
PTNode node[MAX_TREE_SIZE];
int count;
}PTree;
//树的孩子兄弟表示结点结构定义
typedef struct node{
int data;
struct node *firstchild;
struct node *rightsib;
}BTNode,*BTree;
//初始化树(双亲表示法)
void init_ptree(PTree *tree)
{
tree->count=-1;
}
//初始化树的结点(孩子兄弟表示法)
BTNode GetTreeNode(int x)
{
BTNode t;
t.data=x;
t.firstchild=t.rightsib=NULL;
return t;
}
//树的前序遍历(递归)
void preorder(BTNode *T)
{
if(T!=NULL)
{
printf("%d",T->data);
preorder(T->firstchild);
preorder(T->rightsib);
}
}
//树的前序遍历(非递归)
void preorder2(PTree T)
{
int i;
for(i=0;i<T.count;i++)
{
printf("%d",T.node[i].data);
}
}
//树的后序遍历(递归)
void inoeder(BTNode *T)
{
if(T!=NULL)
{
inoeder(T->firstchild);
printf("%d",T->data);
inoeder(T->rightsib);
}
}
//树后序遍历(非递归)
void inoeder2(PTree T)
{
int i;
for(i=T.count-1;i>=0;i--)
{
printf("%d",T.node[i].data);
}
}
//层次遍历、
void level(PTree T)
{
int i;
for(i=0;i<T.count;i++)
{
printf("%d",T.node[i].data);
}
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define MAX_TREE_SIZE 100
//树的双亲表示结点结构定义
typedef struct
{
int data;
int parent;
}PTNode;
//双亲表示法树
typedef struct
{
PTNode node[MAX_TREE_SIZE];
int count;
}PTree;
//树的孩子兄弟表示结点结构定义
typedef struct node{
int data;
struct node *firstchild;
struct node *rightsib;
}BTNode,*BTree;
//初始化树(双亲表示法)
void init_ptree(PTree *tree)
{
tree->count=-1;
}
//初始化树的结点(孩子兄弟表示法)
BTNode GetTreeNode(int x)
{
BTNode t;
t.data=x;
t.firstchild=t.rightsib=NULL;
return t;
}
//树的前序遍历(递归)
void preorder(BTNode *T)
{
if(T!=NULL)
{
printf("%d",T->data);
preorder(T->firstchild);
preorder(T->rightsib);
}
}
//树的前序遍历(非递归)
void preorder2(PTree T)
{
int i;
for(i=0;i<T.count;i++)
{
printf("%d",T.node[i].data);
}
}
//树的后序遍历(递归)
void inoeder(BTNode *T)
{
if(T!=NULL)
{
inoeder(T->firstchild);
printf("%d",T->data);
inoeder(T->rightsib);
}
}
//树后序遍历(非递归)
void inoeder2(PTree T)
{
int i;
for(i=T.count-1;i>=0;i--)
{
printf("%d",T.node[i].data);
}
}
//层次遍历、
void level(PTree T)
{
int i;
for(i=0;i<T.count;i++)
{
printf("%d",T.node[i].data);
}