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

📄 bst.h

📁 这是用vc编写的二叉树排序算法 希望大家多给意见 是数据结构的一种算法
💻 H
字号:
// BST.h: interface for the BST class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_BST_H__757C29B8_E83D_4FE3_9B9F_DF3BBACA6A3B__INCLUDED_)
#define AFX_BST_H__757C29B8_E83D_4FE3_9B9F_DF3BBACA6A3B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include"binnode1.h"
using  namespace std;
class BST  
{
public:
	void downprint();
	void upprint();
	
	BST(){root=NULL;nodecount=0;}
	virtual ~BST(){clearhelp(root);}
	void clear()
	{
		clearhelp(root);root=NULL;nodecount=0;}
	bool insert(const int& e){
	/*	if(nodecount==0)
		{
			root=new binnode(e);
			nodecount++;
			return true;
		}
		else{
		root=inserthelp(root,e);
		nodecount++;
		return true;*/
        inserthelp(root,e);
		return true;
	}
	bool remove(const int& k){
		binnode* t=NULL;
		root=removehelp(root,k,t);
		nodecount++;
		return true;
	}
	bool removeany(int& e){
		if(root==NULL)return false;
		binnode* t;
		root=deletemin(root,t);
		e=t->val();
		delete t;
		nodecount--;
		return true;
	}
	bool find(const int& k,int& e)const{
		return findhelp(root,k,e);}
	int size(){
		return nodecount;}
	void print()const{
		if(root==NULL)cout<<"The BST is empty.\n";
		else printhelp(root,0);
	}
private:
	binnode* root;
	int nodecount;
	void clearhelp(binnode*);
	void inserthelp(binnode*&,const int&);
	binnode* deletemin(binnode*,binnode*&);
	binnode* removehelp(binnode*,const int&,binnode*&);
	bool findhelp(binnode*,const int&,int&)const;
	void printhelp(binnode*, int)const;



protected:
	void down(binnode* root);
	void up(binnode* root);
};

#endif // !defined(AFX_BST_H__757C29B8_E83D_4FE3_9B9F_DF3BBACA6A3B__INCLUDED_)

⌨️ 快捷键说明

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