【数据结构】判断二叉树是否为完全二叉树(利用队列)

队列代码:
链接: 队列代码.
判断是否为二叉树代码:
在这里插入图片描述

//判断是不是完全二叉树
bool judje(btree* root){
    
    
	queue* qe;
	init(qe);
	if (root){
    
    
		push(qe, root);
	}
	while (qe != NULL){
    
    
		btree* front = top(root);
		pop(front);
		if (front){
    
    
			push(qe, front->_left);
			push(qe, front->_right);
		}
		else{
    
    
			break;
		}
	}
	//判断剩下的队列里是否有非空
	while (qe){
    
    
		btree* front = top(qe);
		pop(qe);
		if (front != NULL){
    
    
			return false;
		}
	}
	return true;
}

猜你喜欢

转载自blog.csdn.net/zhaocx111222333/article/details/114990865