⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bitrleiterator.h

📁 包含各种测试,查找和算法等代码,如冒泡算法,树的遍历,链表,队列,堆栈等
💻 H
字号:
#include "LinQueue.h"							//包含链式队列类

template <class T> class BiTrLeIterator: public BiTreeIterator<T>
{
protected:
	LinQueue<BiTreeNode<T> *> Q;		// 保存二叉树结点指针的队列
public:
	BiTrLeIterator(BiTreeNode<T>* &tree):
	  BiTreeIterator<T>(tree){}

	virtual void Next(void);
	virtual void Reset(void);
};

template <class T>
void BiTrLeIterator<T>::Reset(void)
{
	if(root == NULL) iteComplete = 1;	
	else  iteComplete = 0;

	if(root == NULL) return;
	current = root;							//根结点指针为当前结点指针
	if(root->Left() != NULL) Q.Append(root->Left());//左子树入队列
	if(root->Right() != NULL) Q.Append(root->Right());//右子树入队列
}

template <class T>
void BiTrLeIterator<T>::Next(void)
{
	if(iteComplete == 1)
	{
		cout << "已到二叉树尾!" << endl;
		exit(0);
	}
	if(Q.NotEmpty())
	{
		current = Q.Delete();				//出队列取得当前结点指针
		//左子树的根结点指针入队列
		if(current->Left() != NULL) Q.Append(current->Left());
		//右子树的根结点指针入队列
		if(current->Right() != NULL) Q.Append(current->Right());
	}
	else
		iteComplete = 1;					//队列空时置结束标记为1
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -