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

📄 pex11_2.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 CPP
字号:
#include <iostream.h>
#pragma hdrstop

#include "treenode.h"
#include "treelib.h"
#include "bstree.h"

// traverse tree in RNL order
template <class T>	
void RNL(TreeNode<T> *tree, void visit(T& item))
{
	// if tree is NULL, return
	if (tree != NULL)
	{
		// visit the right subtree
		RNL(tree->Right(),visit);
		// visit the node
		visit(tree->data);
		// visit the left subtree
		RNL(tree->Left(),visit);
	}
}

// print the character data in a tree node
void print (int& elem)
{
	cout << elem << "  ";
}

void main(void)
{
	// we create binary search tree t
	BinSTree<int> t;
	int i,value;
	
	// read 10 integer values and insert each into
	// binary search tree t
	for(i=0;i < 10;i++)
	{
		cin >> value;
		t.Insert(value);
	}
	
	// traverse the tree in RNL order, printing each node
	RNL(t.GetRoot(),print);
	cout << endl;
}

/*
<Run>

45 27 4 5 18 78 9 3 5 55
78  55  45  27  18  9  5  5  4  3
*/

⌨️ 快捷键说明

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