资源简介
C++ 数据结构 算法B+树 实现。 实现了 B+树的初始化 插入 遍历 删除

代码片段和文件信息
#include “BPlusTree.h“
#include
#include
#include
int M_WAY = 3;
int NODE_CAPACITY = M_WAY+1;
////////////////////////////////////////////////////
LeaveNode::LeaveNode()
{
m_next = NULL;
m_prev = NULL;
m_value = new double[NODE_CAPACITY];
}
LeaveNode::~LeaveNode()
{
}
void LeaveNode::Insert(int key double value)
{
assert(m_currentSize < NODE_CAPACITY);
for (int i = 0; i < m_currentSize; ++i)
{
if (key <= m_key[i]) //找到插入点
{
//后续所有节点后移一个下标对应指针同步操作
for (int j = m_currentSize - 1; j >= i; --j)
{
m_key[j + 1] = m_key[j];
m_value[j + 1] = m_value[j];
}
m_key[i] = key;
m_value[i] = value;
m_currentSize++;
return;
}
}
m_key[m_currentSize] = key;
m_value[m_currentSize] = value;
m_currentSize++;
}
void LeaveNode::Split(Node* &_left Node* &_right)
{
assert(m_currentSize == NODE_CAPACITY);
LeaveNode* pNew = new LeaveNode;
int leftCount = (int)ceil((M_WAY+1)/2.0);
int rightCount = m_currentSize - leftCount;
int index = 0;
while(index < leftCount)
{
pNew->Insert(m_key[index] m_value[index]);
index++;
}
//原节点剔除分裂到新节点的数据后,继续保留,充当分裂的第二节点
while(index < m_currentSize)
{
m_key[index-leftCount] = m_key[index];
m_value[index-leftCount] = m_value[index];
++index;
}
//更新m_currentSize值
m_currentSize = rightCount;
//更新双向链表指针
if(this->GetPrev() != NULL)
{
this->GetPrev()->SetNext(this);
}
pNew->SetPrev(this->GetPrev());
pNew->SetNext(this);
this->SetPrev(pNew);
_right = this;
_left = pNew;
}
Node* LeaveNode::GetMinLeaveNode()
{
return this;
}
bool LeaveNode::Search(int key double &value Node *&_valueNode)
{
for (int i = 0; i < m_currentSize; ++i)
{
if (key == m_key[i])
{
value = m_value[i];
_valueNode = this;
return true;
}
else if (key < m_key[i])
{ //进入此逻辑,说明查无此KEY
break;
}
}
return false;
}
bool LeaveNode::Search(int key1 int key2 double* result int& size)
{
bool bFind = false;
for (int i = 0; i < m_currentSize; ++i)
{
if (m_key[i] >= key1 && m_key[i] <= key2)
{
result[size] = m_value[i];
size++;
if(!bFind)
{
bFind = true;
}
}
}
return bFind;
}
bool LeaveNode::Delete(int key)
{
for (int i = 0; i < m_currentSize; ++i)
{
if (key == m_key[i])//找到待删除元素
{
//后续所有节点前移一个下标对应指针同步操作
for (int j = i; j {
m_key[j] = m_key[j+1];
m_value[j] = m_value[j+1];
}
m_currentSize--;
return true;
}
else if (key < m_k
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-04-16 16:38 B+Tree\
目录 0 2019-04-16 16:35 B+Tree\data\
文件 311 2019-04-16 16:35 B+Tree\data\input.txt
文件 513 2019-04-16 16:38 B+Tree\Delete Redundant Files.bat
目录 0 2019-04-16 16:39 B+Tree\project\
文件 3683 2019-04-16 16:39 B+Tree\project\project_v100.vcxproj
文件 1166 2019-04-16 16:39 B+Tree\project\project_v100.vcxproj.filters
文件 870 2019-04-16 16:35 B+Tree\project\Solution_v100.sln
目录 0 2019-04-16 16:38 B+Tree\src\
文件 9430 2019-04-16 16:38 B+Tree\src\BPlusTree.cpp
文件 3626 2019-04-16 16:38 B+Tree\src\BPlusTree.h
文件 470 2019-04-16 16:38 B+Tree\src\input.txt
文件 665 2019-04-16 16:38 B+Tree\src\makefile
文件 3644 2019-04-16 16:38 B+Tree\src\Test.cpp
相关资源
- C++获取计算机的CPU ID,硬盘序列号等
- C++头文件转delphi工具 + 源码
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- 学校超市选址问题(数据结构C语言版
- VC++MFC小游戏实例教程(实例)+MFC类库
- 数据结构,迷宫问题C语言版源代码
- DSDEMO-C演示(数据结构C语言版 严蔚敏
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- 数据结构 图的遍历源代码
评论
共有 条评论