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

📄 exam7-2-2.cpp

📁 包含各种测试,查找和算法等代码,如冒泡算法,树的遍历,链表,队列,堆栈等
💻 CPP
字号:
#include <iostream.h>
#include <stdlib.h>

#include "BiTreeNode.h"
//#include "BiTreetraverse.h"
#include "BiTreeLib2.h"

const MaxStackSize = 100;
typedef BiTreeNode<char> DataType;
#include "SeqStack2.h"

void NotRecurPreOrder(DataType *t, void Visit(char item))
//使用Visit(item)函数非递归前序遍历二叉树t
{
	SeqStack stack;
	DataType *p;

	stack.Push(t);
	while(stack.NotEmpty())
	{
		p = stack.Pop();
		Visit(p->data);

		if(p->Right() != NULL)
			stack.Push(p->Right());

		if(p->Left() != NULL)
			stack.Push(p->Left());
	}
}

void MakeCharTree(BiTreeNode<char>*  &root)
{
	BiTreeNode<char> *b, *c, *d, *e, *f, *g, *null = NULL;

	g = GetTreeNode('G');
	d = GetTreeNode('D', null, g);
	b = GetTreeNode('B', d);
	e = GetTreeNode('E');
	f = GetTreeNode('F');
	c = GetTreeNode('C', e, f);
	root = GetTreeNode('A', b, c);
}

void Printchar(char item)
{
	cout << item << " ";
}

void main(void)
{
	BiTreeNode<char> *root1;
	MakeCharTree(root1);

	cout << "递归的前序遍历结点次序为:   ";
	PreOrder(root1, Printchar);

	cout << "\n非递归的前序遍历结点次序为: ";
	NotRecurPreOrder(root1, Printchar);

	int c = LeafNum(root1);
	cout << "c = " << c << endl;
	Destroy(root1);
}

⌨️ 快捷键说明

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