📄 bst.h
字号:
// BST.h: interface for the BST class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_BST_H__A81B8773_7593_46D8_B16C_E7E6BA8BCE0D__INCLUDED_)
#define AFX_BST_H__A81B8773_7593_46D8_B16C_E7E6BA8BCE0D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include<iostream>
using namespace std;
class BST;
class BstNode
{
friend class BST;
public:
BstNode(const int d,BstNode *L=NULL,BstNode *R=NULL)
:data(d),leftc(L),rightc(R){}
BstNode(){data = 0;leftc = rightc = NULL;}
~BstNode(){}
protected:
int data;
BstNode *leftc,*rightc;
};
class BST
{
public:
BST():root(NULL){}
~BST();
void PrintTree() { PrintTree(root); }
void PrintTree1() { PrintTree1(root); }
void PrintTree2() { PrintTree2(root); }
void Insert(const int d) { Insert(d,root); }
bool Find ( const int d )const { return Find(d,root)!=NULL; }
void Remove(const int d) { Remove(d,root); }
int Min() { return Min(root)->data; }
int Max() { return Max(root)->data; }
BstNode * Find(const int d,BstNode *ptr)const;
BstNode * Getroot();
void Output(){ Output(root);}
int CountLeaf(){return leaf(root);}
int Hight(){return hight(root);}
private:
BstNode *root;
void MakeEm ( BstNode *&ptr );
void PrintTree ( BstNode *&ptr )const;
void PrintTree1 ( BstNode *&ptr )const;
void PrintTree2 ( BstNode *&ptr )const;
void Insert ( const int x,BstNode *&ptr );
void Remove ( const int x,BstNode *&ptr );
BstNode * Min( BstNode *ptr )const;
BstNode * Max( BstNode *ptr )const;
void Output(BstNode *&ptr)const;
int leaf(BstNode *&ptr);
int hight(BstNode *&ptr);
};
#endif // !defined(AFX_BST_H__A81B8773_7593_46D8_B16C_E7E6BA8BCE0D__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -