Before the implementation of binary tree traversal, the recursive version is used, which is relatively simple.
This time, I implemented it in a non recursive version. The basic operation to the stack is needed.

## Preorder

According to what we have learned before, preorder is actually to visit first, then traverse the left subtree, and then traverse the right subtree.
Draw a picture to explain:

```void PreOrderByLoop(TreeNode* root)
{
if(root==NULL)
{
return;
}
TreeNode* cur=root;
SeqStack s;
TreeNode* value;
SeqStackInit(&s);
while(SeqStackEmpty(&s)!=0||cur!=NULL)
{
while(cur!= NULL)
{
if(cur!=NULL)
{
printf("%c ",cur->data);
SeqStackPush(&s,cur);
cur=cur->lchild;
}
}
SeqStackTop(&s,&value);
SeqStackPop(&s);
cur=value->rchild;
}
}
```

## Middle order

The idea of the middle order is basically similar to that of the front order, except that the stack entry and access order are changed.
Draw a picture to explain:

```void InOrderByLoop(TreeNode* root)
{
if(root==NULL)
{
return;
}
TreeNode* cur=root;
SeqStack s;
TreeNode* value;
SeqStackInit(&s);
while(SeqStackEmpty(&s)!=0||cur!=NULL)
{
while(cur!= NULL)
{
if(cur!=NULL)
{
SeqStackPush(&s,cur);
cur=cur->lchild;
}
}
SeqStackTop(&s,&value);
printf("%c ",value->data);
SeqStackPop(&s);
cur=value->rchild;
}
}
```

## Post order

The latter order has one more judging condition than the former order and the middle order, that is, the condition to access the node. Either the node has no right child, or it returns to the node after being accessed by the right child. So you need a prev pointer to record who the last visited node was.

```void PostOrderByLoop(TreeNode* root)
{
if(root==NULL)
{
return;
}
TreeNode* cur=root;
TreeNode* prev=NULL;
SeqStack s;
TreeNode* value=NULL;
SeqStackInit(&s);
while(SeqStackEmpty(&s)!=0||cur!=NULL)
{
while(cur!= NULL)
{
if(cur!=NULL)
{
SeqStackPush(&s,cur);
cur=cur->lchild;
}
}
SeqStackTop(&s,&value);
if(value->rchild==NULL||value->rchild==prev)
{
//If the value at this time has no right child, you can directly access it.
//Or at this time, the right child of value has been accessed and can access it directly
printf("%c ",value->data);
prev=value;
SeqStackPop(&s);
}
else
{
cur=value->rchild;
}
}
}
```