1 Star 0 Fork 0

poodkcc / o3d

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bsTree.h 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
#pragma once
#ifndef O3D_BS_TREE_H
#define O3D_BS_TREE_H
template<typename T>
class BSTree {
public:
T val_;
BSTree* leftNode_ = nullptr;
BSTree* rithrNode_ = nullptr;
void add(BSTree& it) {
this->add(&it);
}
void add(BSTree* it) {
if (!leftNode_ && it->val_ <= this->val_) {
leftNode_ = it;
return;
}
if (!rithrNode_ && it->val_ > this->val_) {
rithrNode_ = it;
return;
}
if (it->val_ <= this->val_) {
this->leftNode_->add(it);
} else {
this->rithrNode_->add(it);
}
}
};
template<>
class BSTree<unsigned char> {
public:
BSTree<unsigned char>(const uint8_t& ival) :val_(ival) {
}
BSTree<unsigned char>() : val_(0) {
}
unsigned char val_;
BSTree <unsigned char>* leftNode_ = nullptr;
BSTree <unsigned char>* rithrNode_ = nullptr;
void add(BSTree <unsigned char>& it) {
this->add(&it);
}
void add(BSTree <unsigned char>* it) {
if (!leftNode_ && it->val_ <= this->val_) {
leftNode_ = it;
return;
}
if (!rithrNode_ && it->val_ > this->val_) {
rithrNode_ = it;
return;
}
if (it->val_ <= this->val_) {
this->leftNode_->add(it);
} else {
this->rithrNode_->add(it);
}
}
};
#endif
1
https://gitee.com/poodkcc/o3d.git
git@gitee.com:poodkcc/o3d.git
poodkcc
o3d
o3d
master

搜索帮助