資源簡介
完整的C/C++時序的B+樹(數(shù)據(jù)庫系統(tǒng)實現(xiàn)實驗,用于做數(shù)據(jù)索引)
工程是VS2015中開發(fā),使用VS可以打開。菜單化,自動生成模擬數(shù)據(jù)等等。

代碼片段和文件信息
#include?
#include?
#include?“BTreeIndex.h“
#include?“Record.h“
void?printMenu();
//function?declares
//可以忽略了,這些都是測試用的。請直接運行程序就好。
void?t_empty();
void?t_1_to_10();
void?t_btree4();
void?t_del();
int?main()
{
//t_empty();
//t_add();
//t_1_to_10();
//t_btree4();
//t_del();
Database?db(“dbFile“);
//定義一個BTree索引數(shù)據(jù)表。
BTreeIndex?indexDB(3);
//數(shù)據(jù)記錄,用于存放輸入的臨時數(shù)據(jù)。
Record?record;
//用于存放輸入的臨時數(shù)據(jù)。
int?key;
//打印命令。
printMenu();
//命令號
int?cmd?=?-1;
//接受命令。
while?(cin?>>?cmd)?{
switch?(cmd)
{
//1:新增數(shù)據(jù)?格式(key?value)
case?1:
cout?<“please?input?key?and?value:“;
cin?>>?record.key?>>?record.content;
indexDB.add(record.key?record);
break;
//2:刪除數(shù)據(jù)?格式(key)
case?2:
cout?<“please?input?key:“;
cin?>>?key;
indexDB.del(key);
break;
//3:查詢數(shù)據(jù)?格式(key)
case?3:
cout?<“please?input?key:“;
cin?>>?key;
record.key?=?-1;
indexDB.find(key?record);
if?(record.key?!=?-1)?{
cout?<“Record[key=“?< }
else?{
cout?<“Record?with?key=“?< }
break;
//4:打印B樹索引“?< case?4:
indexDB.getBTree()->print();
break;
case?5:
indexDB.getBTree()->printAllLeaf();
break;
default:
cout?<“invalid?cmmand!“?< break;
}
printMenu();
}
return?0;
}
//打印功能菜單
void?printMenu()?{
cout?< cout?<“1:新增數(shù)據(jù)?格式(key?value);“?< cout?<“2:刪除數(shù)據(jù)?格式(key);“?< cout?<“3:查詢數(shù)據(jù)?格式(key);“?< cout?<“4:打印B樹索引“?< cout?<“5:打印葉子結(jié)點“?<}
void?t_del()?{
BTree?btree(3);
for?(int?i?=?1;?i?<=?3;?i++)?{
btree.add(10?*?i?10?*?i);
btree.printAllLeaf();
}
btree.add(25?25);
btree.printAllLeaf();
btree.add(45?45);
btree.printAllLeaf();
btree.add(61?61);
btree.printAllLeaf();
btree.add(63?63);
btree.printAllLeaf();
btree.add(65?65);
btree.printAllLeaf();
btree.add(64?64);
btree.printAllLeaf();
btree.add(62?62);
btree.printAllLeaf();
btree.add(82?82);
btree.printAllLeaf();
btree.add(84?84);
btree.printAllLeaf();
btree.add(86?86);
btree.printAllLeaf();
btree.add(88?88);
btree.printAllLeaf();
btree.add(85?85);
cout?<“刪除65之前-------------------------------------“?< btree.print();
btree.printAllLeaf();
cout?<“刪除65之后-------------------------------------“?< btree.del(65);
btree.print();
btree.printAllLeaf();
//合并左結(jié)點
//btree.del(100);
//btree.print();
//btree.printAllLeaf();
//合并右結(jié)點
btree.del(85);
btree.print();
btree.printAllLeaf();
btree.del(80);
btree.print();
btree.printAllLeaf();
//構(gòu)造導(dǎo)致父結(jié)點也合并的情況
//內(nèi)部結(jié)點合并并且通過借結(jié)點實現(xiàn)(向左借)
btree.del(61);
btree.print();
btree.printAllLeaf();
//內(nèi)部結(jié)點合并并且通過借結(jié)點實現(xiàn)(向右借)
btree.del(50);
btree.print();
btree.printAllLeaf();
btree.del(6
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-01-01?10:38??BTree\
?????目錄???????????0??2016-01-01?10:38??BTree\.vs\
?????目錄???????????0??2016-01-01?10:38??BTree\.vs\BTree\
?????目錄???????????0??2016-01-01?10:38??BTree\.vs\BTree\v14\
?????文件???????47104??2015-12-28?19:53??BTree\.vs\BTree\v14\.suo
?????目錄???????????0??2016-01-01?10:38??BTree\BTree\
?????文件????12910592??2015-12-28?19:53??BTree\BTree.sdf
?????文件????????1297??2015-12-10?23:38??BTree\BTree.sln
?????文件???????34790??2015-12-28?19:53??BTree\BTree\BTree.h
?????文件????????7497??2015-12-23?20:05??BTree\BTree\BTree.vcxproj
?????文件????????1399??2015-12-23?20:05??BTree\BTree\BTree.vcxproj.filters
?????文件????????2176??2015-12-24?18:49??BTree\BTree\BTreeIndex.h
?????文件????????2289??2015-12-24?18:44??BTree\BTree\Databa
?????目錄???????????0??2016-01-01?10:38??BTree\BTree\Debug\
?????文件?????????728??2015-12-28?10:52??BTree\BTree\Debug\BTree.Build.CppClean.log
?????文件????????4015??2015-12-28?10:52??BTree\BTree\Debug\BTree.log
?????文件???????20622??2015-12-28?10:52??BTree\BTree\Debug\BTree.obj
?????目錄???????????0??2016-01-01?10:38??BTree\BTree\Debug\BTree.tlog\
?????文件?????????159??2015-12-28?10:52??BTree\BTree\Debug\BTree.tlog\BTree.lastbuildstate
?????文件????????1186??2015-12-28?10:52??BTree\BTree\Debug\BTree.tlog\CL.command.1.tlog
?????文件???????22318??2015-12-28?10:52??BTree\BTree\Debug\BTree.tlog\CL.read.1.tlog
?????文件?????????924??2015-12-28?10:52??BTree\BTree\Debug\BTree.tlog\CL.write.1.tlog
?????文件????????1176??2015-12-28?10:52??BTree\BTree\Debug\BTree.tlog\li
?????文件????????3000??2015-12-28?10:52??BTree\BTree\Debug\BTree.tlog\li
?????文件?????????454??2015-12-28?10:52??BTree\BTree\Debug\BTree.tlog\li
?????文件??????566060??2015-12-28?10:52??BTree\BTree\Debug\main.obj
?????文件??????470016??2015-12-28?10:52??BTree\BTree\Debug\vc140.idb
?????文件??????495616??2015-12-28?10:52??BTree\BTree\Debug\vc140.pdb
?????文件????????4850??2015-12-24?18:53??BTree\BTree\main.cpp
?????文件????????1496??2015-11-24?22:27??BTree\BTree\ReadMe.txt
?????文件?????????285??2015-12-23?21:25??BTree\BTree\Record.h
............此處省略4個文件信息
評論
共有 條評論