Monday, 28 September 2015

B Trees in c/c++ source code, Trees source code in c/c++, source code,

B Trees in c/c++ source code, Trees source code in c/c++, source code,
// btrees.cpp : Defines the entry point for the console application.
//



B Trees in c/c++ source code, Trees source code in c/c++, source code, 

For More:>  Sorting......, selection sort..., merge sort....., insertion Sort....., General Tree....Binary Tree..... and many more.....



#include "stdafx.h"

/*A program to implement B-TREE.
   */

#include<iostream>
using namespace std;


class node;
struct pair
{
int key;
node *next;
}pair;
class node
{
public:
node *father;
int noofkeys;
    pair data[MAX];
node *first;
node();
void insert_in_node(pair x);
pair splitnode(pair x);
int leaf_node();
node *nextindex(int x);
void display();
};
void node::display()
{
int i;
cout<<"(";
for(i=0;i<noofkeys;i++)
cout<<data[i].key<<" ";
cout<<")";
}
node* node::nextindex(int x)
{
if(x<data[0].key)
return first;
for(int i=0;i<noofkeys;i++)
{
if(x<=data[i].key)
return (data[i-1].next);
}
return (data[i-1].next);
}
int node::leaf_node()
{
if(data[0].next==NULL)
return 1;
return 0;
}


 void node::insert_in_node(pair mypair)
   {
int i;
for(i=noofkeys-1;i>=0 && data[i].key>mypair.key;i--)
data[i+1]=data[i];
data[i+1]=mypair;
noofkeys++;
   }

node::node()
{
 for(int i=0;i<=MAX;i++)
  data[i].next=NULL;
 noofkeys=0;
 father=NULL;
 first=NULL;
}

class btree
 {
int mkeys;
node *root;
public:
btree(int n)
  {
mkeys=n;
root=NULL;
  }
void insert(int x);
void displaytree();
 };

void main()
   {
 int n,i,x,op;
 node *p;

 cout<<"\nmaximum number of keys in a node ? :";
 cin>>n;
 btree b(n);
 do
{
cout<<"\n\n1)Insert\n2)Print\n3)Quit";
cout<<"\nEnter your choice : ";
cin>>op;
switch(op)
  {
case 1: cout<<"\nEnter a data : ";
cin >> x;
b.insert(x);
break;

case 2:
b.displaytree();
  break;
}
 }while(op!=3);
}

Dear Readers if you have any query/question feel free to ask me via comment box given below. Also Follow us on social media site and share that post with your friends. - See more at: http://onlinecomputercafe.blogspot.com 

useful tutorial keep it up...
EmoticonEmoticon

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:o
:>)
(o)
:p
:-?
(p)
:-s
8-)
:-t
:-b
b-(
(y)
x-)
(h)

LinkWithin