For example str---A (B (D (, G)), C, (e,f))
The scan uses the bracket notation to denote the binary tree string read to the symbol CH
Save parent nodes with a stack
The introduction of a variable K function is to specify whether the left child or the right child will be processed afterwards
K=1 treatment left child k=2 treatment right child
The situation is as follows
Create a node when a real letter is encountered
1 Encounters ch= Opening parenthesis adds the previously created node to the stack as a parent, k=1, indicating that the node that follows is the left child
2 Encounter ch= comma indicates that the node created after it is the right child node (the node refers to the actual letter otherwise invalid) k=2
3 encountered ch= closing parenthesis indicates that the left and right child of the node in the stack has been processed, back to the stack.
But the creation process is to always stack top elements as parent nodes.
Creation of data structure two fork tree