?? avltree.h
字號(hào):
//this is avl tree class
#include "AVLNode.h"
class avlTree//平衡二叉樹類
{
public:
avlTree();//構(gòu)造函數(shù)
~avlTree();//析構(gòu)函數(shù)
void add(Index value);
bool remove(Index value);
void deleteAllValue();
avlNode* findValue(Index val);
avlNode* root;
};
avlTree::avlTree():root(0)
{}//建立空樹
avlTree::~avlTree()
{
if (root!=NULL) deleteAllValue();
}
void avlTree::add(Index value)
{//向平衡的avl樹添加元素
if(root==NULL)
root=new avlNode(value);
else{
if(root->findNodeValue(value)!=NULL)
return;
root->add(root,value);
}
}
bool avlTree::remove(Index val)
{//從avl樹中刪除一個(gè)元素
avlNode* eNode=NULL;
int flag=0;
if (root)
root=root->remove(val,eNode,flag);
if (eNode)
{
delete eNode;
return true;
}
else
return false;
}
void avlTree::deleteAllValue()
{//刪除avl樹的全部元素
if(root!=NULL)
{
root->release();
delete root;
root=NULL;
}
}
avlNode* avlTree::findValue(Index val)
{//查找val的節(jié)點(diǎn)值
avlNode* found=root->findNodeValue(val);
if (found==NULL)
return NULL;
else
return found;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -