#include<stdio.h>
#include<malloc.h>
#include<stdbool.h>
#define MaxSize 100
typedef char ElemType;
typedef struct node
{
ElemType data;
struct node* lchild;
struct node* rchild;
}BTNode;
// 链栈
typedef struct STACK {
char data;
struct STACK* next;
}StackNode, * Stack;
int flag=1; // 标记符
Stack L; // 链栈头节点指针
// 入栈
ElemType PushStack(char x)
{
Stack top;
top = (Stack)malloc(sizeof(StackNode));
top->data = x;
top->next = L; // 第一次是让一开始的头节点存入元素,尾巴指向NULL已经初始化好
L = top; // 之后便是创建新的链栈节点和之前的串起来
}
// 出栈
char PopStack()
{
ElemType x;
if (L->next == NULL) // 栈空
{
printf("出栈完毕\n");
exit(-1);
}
else {
Stack p;
x = L->data;
p = L; // 让原来的L变成P
L = p->next; // 原来头节点next指向的变成新的头节点
free(p); // 释放原来的头节点
return x; // 返回原来头节点里头的元素
}
}
BTNode* CreateBTNode(BTNode* b
c 二叉树遍历指定节点输出路径
最新推荐文章于 2024-01-25 20:18:16 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)