Btree

  • July 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Btree as PDF for free.

More details

  • Words: 245
  • Pages: 5
// b trees import java.io.*; class bnode { int data1,data2; bnode lptr,mptr,rptr,parent; void bnode() { this.data1=0; this.data2=0; this.lptr=null; this.mptr=null; this.rptr=null; this.parent=null; } } class btree { bnode root=null; bnode p,p1,x; bnode prev; void insert(int ele) { bnode temp=new bnode(); temp.data1=ele; if(root==null) { root=temp; } else { p1=root; while(p1!=null) { prev=p1; if(temp.data1p1.data1) && (temp.data1
} p1=prev; while(p1!=null) { if(p1.data2==0) { if(temp.data1
if(t.data1p.data1) && (t.data1
p.lptr.lptr=n1; if(n1!=null) p.lptr.lptr.parent=p.lptr; p.lptr.rptr=n2; if(n2!=null) p.lptr.rptr.parent=p.lptr; p.data1=p.data2; p.data2=0; p.rptr=new bnode(); p.rptr=t; p.rptr.parent=p; } return p; }

void display(bnode temp) { if(temp!=null) { display(temp.lptr); display(temp.mptr); display(temp.rptr); System.out.println(" data1::"+temp.data1+" data2::"+temp.data2 +" address::"+temp+" parent :"+temp.parent); } } } class btree_main { public static void main(String[] args)throws IOException { System.out.println("B-Trees"); DataInputStream in=new DataInputStream(System.in); btree bt=new btree(); int x,ch; do { System.out.println("Enter the element"); x=Integer.parseInt(in.readLine()); bt.insert(x);

System.out.println("To continue...press 1"); ch=Integer.parseInt(in.readLine()); }while(ch==1); } }

Related Documents

Btree
July 2020 85
Btree
June 2020 48
Btree
November 2019 47