#include <stdio.h>
#include<stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//二叉树的存储结构
typedef struct TreeNode
{
char data;
TreeNode* lchild;
TreeNode* rchild;
}BinTree;
#define ElementType BinTree*
//栈的存储结构
typedef struct node
{
ElementType data;
struct node* next;
}Stack;
Stack* creatStack()//创建一个带头的栈
{
Stack* s=(Stack*)malloc(sizeof(node));
s->next=NULL;
return s;
}
bool isEmpty(Stack* s)//判断栈是否为空
{
if(s->next==NULL) return true;
return false;
}
void push(Stack* s,ElementType value)//入栈
{
Stack* New=(Stack*)malloc(sizeof(node));
New->data=value;
New->next=s->next;
s->next=New;
}
BinTree* pop(Stack* s)//出栈
{
if(isEmpty(s)==true){
printf("栈空,不能出栈!");
return 0;
}
else{
Stack* p
二叉树的前序,中序,后序的遍历的递归和非递归代码-C语言
最新推荐文章于 2022-07-15 16:20:17 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)