?? avltree.h
字號:
//this is avl tree class
#include "AVLNode.h"
class avlTree//平衡二叉樹類
{
public:
avlTree();//構造函數
~avlTree();//析構函數
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樹中刪除一個元素
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的節點值
avlNode* found=root->findNodeValue(val);
if (found==NULL)
return NULL;
else
return found;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -