B-tree C ++ implementation

Source: Internet
Author: User

Publish a B-Tree Code

 

Code download: http://bluedog.download.csdn.net

 

B-MSO-ascii-font-family: "> there are not many codes on the tree network. I think there is no need to talk about its principles. There are too many books on the Internet. I spent a few days writing one here. If you think it is useful, you can use it. There have been a lot of tests and there should be no major problems. It is defined by two files: binaryminustree. H "> and binaryminustree. INC ">, you only need to include binaryminustree. H "> just fine.

# Include
"Binaryminustree. H"

These two files define several classes, but the only thing you need to know is cbinaryminustree. The definition of this class is as follows:

"Lang =" En-us "> template <typename TK, typename
TV, size_t thd = 10>

Class9.0pt; font-family: "lang =" En-us "> binaryminustreekey

Tk mso-ascii-font-family: "> key"> value type,

Tvmso-ascii-font-family: "> is Val"> value type,

Thd MSO-ascii-font-family: "> half of the node degree, meaning that if your node degree is 21"> there is a font-family: "lang =" En-us "> 21 font-family:" lang = "En-us"> key value, then font-family: "lang =" En-us "> thd should be font-family:" lang = "En-us"> 10

"Lang =" En-us ">

MSO-ascii-font-family: "> There are several methods:

"Lang =" En-us "> bool add (TK
Key, TV Val); // 9.0pt; font-family:; MSO-ascii-font-family: "> Add a keyfont-family:; MSO-ascii-font-family: "> Value

"Lang =" En-us "> bool
Remove (TK key );
// Font-family:; MSO-ascii-font-family: "> delete a key

"Lang =" En-us "> void
Print (); yes "> // MSO; MSO-ascii-font-family:"> Print tree

Void9.0pt; font-family: "lang =" En-us "> clear ();
// Font-family:; MSO-ascii-font-family: "> delete all data

"Lang =" En-us ">

MSO-ascii-font-family: "> there are several other public members:

"Lang =" En-us "> lpbmtn root; yes"> // MSO-ascii-font-family: "> root node

"Lang =" En-us "> size_t keycount; // Number of keywords

"Lang =" En-us "> size_t level; // number of layers in the tree

Size_t nodecount; // Number of Tree nodes

Other functions are not provided. If you have other users who need them, complete them. Haha.

Note: in fact, the principle of B-tree is very simple, and the algorithm description provided in the book is also very clear. However, it is still a bit difficult to write it well. There are many points to pay attention, the tree goes down accidentally.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.