The traversal of the sequence is complete.
Unlike pre-order traversal, middle-order traversal, and post-order traversal, sequence traversal does not use the stack mode, but uses a queue.
The data in the queue, that is, the queueitem is the Binary Search Tree node pointer, which can save the node and easily handle the return value when the stack is empty. That is, null can be returned.
Implemented using a function that accepts a tree-type variable. No return value is returned.
First, the root node of the tree enters the queue, and then the queue is not empty as the condition for loop. in the cycle, a node is first deleted from the queue, and the pointer of the node is obtained through the return value queueitem of deletequeue. this pointer can be processed, such as printing information. then, check the left subtree of the node and whether the right subtree is not empty. In turn, add the pointer of the Left subtree to the queue, and the loop body ends.
With the features of the queue, I feel that the data structure field is really very promising.
void level_inorder_traversal (const tree) <br/>{< br/> queue; <br/> queueitem temp; </P> <p> initializequeue (& Queue ); </P> <p> enqueue (& queue, & tree); <br/> while (! Queueisempty (& Queue) <br/>{< br/> temp = dequeue (& Queue); <br/> print_item (temp-> item ); <br/> If (temp-> left! = NULL) <br/> enqueue (& queue, & temp-> left); <br/> If (temp-> right! = NULL) <br/> enqueue (& queue, & temp-> right); <br/>}