实现一颗二叉树的层序遍历

二叉树的层序遍历(队列实现):

// 层序遍历
	void LevelOrder()
	{
		if(_pRoot == NULL)
			return;
		queue q;
		q.push(_pRoot);
		while(!q.empty())
		{
			Node* pCur = NULL;
			pCur = q.front();
			q.pop();
			cout<_data<<" ";
			if(pCur->_pLeft)
				q.push(pCur->_pLeft);
			if(pCur->_pRight)
				q.push(pCur->_pRight);
		}
		cout<


你可能感兴趣的:(数据结构,刷题库)