请大家帮我解释下此C语言程序中每句的作用

来源:百度知道 编辑:UC知道 时间:2024/05/13 05:04:11
#define M 100
#define Null 0
typedef struct node
{ int data;
struct node *lchild, *rchild;
} bitree;
bitree *que[M];
int front=0, rear=0;
bitree *creat( )
{ bitree *t;
int x;
scanf (“%d”, &x);
if (x= =0)
t=Null;
else
{
t=malloc(sizeof(bitree));
t→data=x;
t→lchild=creat( );
t→rchild=creat( );
}
return t;
}

void inorder( t )
bitree *t;
{ if (t!=Null)
{ inorder (t→lchild);
printf(“%4d”, t→data);
inorder (t→rchild);
}
}

void enqueue(t)
bitree *t;
{ if(front!=(rear+1) % M)
{rear = (rear+1) % M;
que[rear]=t;
}
}

bitree *delqueue( )
{
if (front= =rear)
return Null;
front=(front+1) % M;
return (que[front]);
}

void levorder ( t )
bitree *t;
{ bitree *p;

#define M 100
#define Null 0 //宏定义,在程序中把Null替换成0,M换成100
typedef struct node //结构体类型的节点
{ int data;
struct node *lchild, *rchild; //左孩子和右孩子分别也是节点
} bitree; //二叉树
bitree *que[M];
int front=0, rear=0; //初始化头指针,尾指针
bitree *creat( ) //构造二叉树
{ bitree *t;
int x;
scanf (“%d”, &x);
if (x= =0)
t=Null;
else
{
t=malloc(sizeof(bitree)); //分配内存给新的节点
t→data=x; //赋值
t→lchild=creat( );
t→rchild=creat( );
}
return t;
}

void inorder( t ) //中序遍历二叉树
bitree *t;
{ if (t!=Null)
{ inorder (t→lchild); //递归的方法
printf(“%4d”, t→data);
inorder (t→rchild);
}
}

void enqueue(t) //入队函数
bitree *t;
{ if(front!=(rear+1) % M)
{rear = (rear+1) % M;
que[rear]=t;
}
}

bitree *delqueue(