[Data structure] Use queues to achieve binary tree sequence traversal

Queue code:
Link: Queue code .

The sequence of traversing the binary tree:
Insert picture description here

//层序遍历
void btreelevelorder(btree* root){
    
    
	queue* qe;
	init(qe);
	if (root){
    
    
		push(qe,root);
	}
	while (qe != NULL){
    
    
		btree* qenode = top(qe);
		pop(qenode);
		printf("%d", qenode->_data);
		if (root->_left)
			push(qe, root->_left);
		if (root->_right)
			push(qe, root->_right);
	}
}

Guess you like

Origin blog.csdn.net/zhaocx111222333/article/details/114990546