```c
#include<stdio.h>
#include<stdlib.h>
typedef struct tnode *BinTree;
struct tnode {
BinTree left, right;
char Data;
};
typedef struct snode *stack;
struct snode {
BinTree data;
stack next;
};
stack creatstack() {
stack s = (stack)malloc(sizeof(struct snode));
s->next=NULL;
return s;
}
int isempty(stack s) {
if (s->next == NULL)
return 1;
else return 0;
}
void push(stack s, BinTree BT) {
stack newnode = (stack)malloc(sizeof(struct snode));
newnode->data = BT;
newnode->next = s->next;
s->next = newnode;
}
BinTree pop(stack s) {
stack tmp = s->next;
BinTree T = s->next->data;
s->next = tmp->next;
free(tmp);
return T;
}
BinTree creatBT() {
char ch;
BinTree BT;
scanf_s("%c", &ch);
if (ch == '#')
BT = NULL;
else {
BT = (BinTree)malloc(sizeof(struct tnode));
BT->Data = ch;
BT->left = creatBT();
BT->right = creatBT();
}
return BT;
}
void inorder(BinTree BT) {
stack s = creatstack();
while (BT || !isempty(s)) {
while (BT) {
push(s, BT);
BT = BT->left;
}
while (!isempty(s)){
BT =pop(s);
printf("%c", BT->Data);
BT = BT->right;
}
}
}
int main() {
BinTree BT;
BT = creatBT();
inorder(BT);
}
#include<stdio.h>
#include<stdlib.h>
typedef struct tnode *BinTree;
struct tnode {
BinTree left, right;
char data;
};
typedef struct node*Node;
struct node {
BinTree data;
Node next;
};
typedef struct qnode* queue;
struct qnode{
Node front, rear;
};
queue creatqueue() {
queue Q = (queue)malloc(sizeof(struct qnode));
Q->front = Q->rear = NULL;
return Q;
}
int isempty(queue Q) {
if (Q->front == NULL)return 1;
else return 0;
}
void add(queue Q,BinTree BT) {
Node newnode = (Node)malloc(sizeof(struct node));
if (isempty(Q)) {
newnode->data = BT;
Q->front = Q->rear=newnode;
newnode->next = NULL;
}
else {
newnode->data = BT;
Q->rear->next = newnode;
newnode->next = NULL;
Q->rear = newnode;
}
}
BinTree Delete(queue Q){
Node tmp = Q->front;
BinTree x = Q->front->data;
if (Q->front->next == NULL) {
Q->front = Q->rear = NULL;
}
else {
Q->front = Q->front->next;
}
free(tmp);
return x;
}
BinTree creatBT() {
BinTree BT;
char ch;
scanf_s("%c", &ch);
if (ch == '#')
BT = NULL;
else {
BT = (BinTree)malloc(sizeof(struct tnode));
BT->data = ch;
BT->left = creatBT();
BT->right = creatBT();
}
return BT;
}
void leverorder(BinTree BT) {
BinTree T=BT;
queue Q = creatqueue();
add(Q, BT);
while (!isempty(Q)) {
T = Delete(Q);
printf("%C", T->data);
if (T->left)add(Q, T->left);
if (T->right)add(Q, T->right);
}
}
int main() {
BinTree BT=creatBT();
leverorder(BT);
}