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

📄 pex11_9.cpp

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

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

#include "wex11_18.h"

void main(void)
{
	// create a binary search tree with data values from a
	BinSTree<int> tree;
	int a[] = {50,35,38,45,32,25,75,65,90,77};
	int i, target;
	TreeNode<int> *newtree;
	
	// build the search tree
	for(i=0;i < 10;i++)
		tree.Insert(a[i]);
		
	// print the search tree
	PrintVTree(tree.GetRoot(),2,50);
	cout << endl << endl << endl;
	
	// enter a target, use TCopyTree to copy the tree
	// and print the new tree vertically
	cout << "Enter the target: ";
	cin >> target;
	newtree= TCopyTree(tree.GetRoot(),target);	
	PrintVTree(newtree,2,50);
}

/*
<Run #1>
                       50

           35                      75

     32          38          65          90

  25                45                77


Enter the target: 40
                       50

           35                      75

                             65          90

                                      77

<Run #2>


                       50

           35                      75

     32          38          65          90

  25                45                77


Enter the target: 77
                       50
*/

⌨️ 快捷键说明

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