B+ tree JAVA source code for implementing Insertion and Deletion

B+ tree JAVA source code for implementing Insertion and Deletion

View Answers

November 15, 2008 at 12:05 AM

Hi friend,


public class BinarytreeDemo{
public static void main(String args[]){
System.out.println(new BTreeDemo().Start());
}
}

class BTreeDemo {

public int Start(){
Tree root;
boolean bool;
int nti;

root = new Tree();
bool = root.Init(16);
bool = root.Print();
System.out.println(100);
bool = root.Print();
System.out.println("After Inserting data is! ");
bool = root.Insert(8);
bool = root.Insert(24);
bool = root.Insert(40);
bool = root.Insert(12);
bool = root.Insert(20);
bool = root.Insert(28);
bool = root.Insert(14);
bool = root.Insert(25);
bool = root.Insert(25);
bool = root.Print();

System.out.println("Search value is: " + root.Search(24));
System.out.println("Search value is: " + root.Search(12));
System.out.println("Search value is: " + root.Search(16));
System.out.println("Search value is: " + root.Search(50));
System.out.println("Search value is: " + root.Search(12));
System.out.println("Search value is: " + root.Search(25));
System.out.println("After deleting data! ");
bool = root.Delete(12);
bool = root.Delete(25);
bool = root.Print();
System.out.println(root.Search(12));
System.out.println("Delete value is: " + root.Delete(12));
System.out.println("Delete value is: " + root.Delete(25));
return 0 ;
}

}

class Tree{
Tree left ;
Tree right;
int key ;
boolean has_left ;
boolean has_right ;
Tree my_null ;

// Initialize a node with a key value and no children
public boolean Init(int v_key){
key = v_key ;
has_left = false ;
has_right = false ;
return true ;
}

// Update the right child with rn
public boolean SetRight(Tree rn){
right = rn ;
return true ;
}

// Update the left child with ln
public boolean SetLeft(Tree ln){
left = ln ;
return true ;
}

public Tree GetRight(){
return right ;
}

public Tree GetLeft(){
return left;
}

public int GetKey(){
return key ;
}

public boolean SetKey(int v_key){
key = v_key ;
return true ;
}

public boolean GetHas_Right(){
return has_right ;
}

public boolean GetHas_Left(){
return has_left ;
}

public boolean SetHas_Left(boolean val){
has_left = val ;
return true ;
}

public boolean SetHas_Right(boolean val){
has_right = val ;
return true ;
}

// This method compares two integers and returns true if they are equal and false

public boolean Compare(int num1 , int num2){
boolean bool ;
int nti ;

bool = false ;
nti = num2 + 1 ;
if (num1 < num2) bool = false ;
else if (!(num1 < nti)) bool = false ;
else bool = true ;
return bool ;
}

November 15, 2008 at 12:06 AM

// Insert a new element in the tree
public boolean Insert(int v_key){
Tree new_node ;
boolean bool ;
boolean cont ;
int keyValue ;
Tree cNode ;

new_node = new Tree();
bool = new_node.Init(v_key) ;
cNode = this ;
cont = true ;
while (cont){
keyValue = cNode.GetKey();
if (v_key < keyValue){
if (cNode.GetHas_Left())
cNode = cNode.GetLeft() ;
else {
cont = false ;
bool = cNode.SetHas_Left(true);
bool = cNode.SetLeft(new_node);
}
}
else{
if (cNode.GetHas_Right())
cNode = cNode.GetRight() ;
else {
cont = false ;
bool = cNode.SetHas_Right(true);
bool = cNode.SetRight(new_node);
}
}
}
return true ;
}

// Delete an element from the tree

public boolean Delete(int v_key){
Tree cNode ;
Tree parent_node ;
boolean cont ;
boolean found ;
boolean is_root ;
int keyValue ;
boolean bool ;

cNode = this ;
parent_node = this ;
cont = true ;
found = false ;
is_root = true ;
while (cont){
keyValue = cNode.GetKey();
if (v_key < keyValue)
if (cNode.GetHas_Left()){
parent_node = cNode ;
cNode = cNode.GetLeft() ;
}
else cont = false ;
else
if (keyValue < v_key)
if (cNode.GetHas_Right()){
parent_node = cNode ;
cNode = cNode.GetRight() ;
}
else cont = false ;
else {
if (is_root)
if ((!cNode.GetHas_Right()) &&
(!cNode.GetHas_Left()) )
bool = true ;
else
bool = this.Remove(parent_node,cNode);
else bool = this.Remove(parent_node,cNode);
found = true ;
cont = false ;
}
is_root = false ;
}
return found ;
}

// Check if the element to be removed will use the, righ or left subtree if one exists

public boolean Remove(Tree p_node, Tree c_node){
boolean bool ;
int auxkey1 ;
int auxkey2 ;

if (c_node.GetHas_Left())
bool = this.RemoveLeft(p_node,c_node) ;
else
if (c_node.GetHas_Right())
bool = this.RemoveRight(p_node,c_node) ;
else {
auxkey1 = c_node.GetKey();
auxkey2 = (p_node.GetLeft()).GetKey() ;
if (this.Compare(auxkey1,auxkey2)) {
bool = p_node.SetLeft(my_null);
bool = p_node.SetHas_Left(false);
}
else {
bool = p_node.SetRight(my_null);
bool = p_node.SetHas_Right(false);
}
}
return true ;
}

public boolean RemoveRight(Tree p_node, Tree c_node){
boolean bool ;

while (c_node.GetHas_Right()){
bool = c_node.SetKey((c_node.GetRight()).GetKey());
p_node = c_node;
c_node = c_node.GetRight() ;
}
bool = p_node.SetRight(my_null);
bool = p_node.SetHas_Right(false);
return true ;
}

public boolean RemoveLeft(Tree p_node, Tree c_node){
boolean bool;

while (c_node.GetHas_Left()){
bool = c_node.SetKey((c_node.GetLeft()).GetKey());
p_node = c_node ;
c_node = c_node.GetLeft() ;
}
bool = p_node.SetLeft(my_null);
bool = p_node.SetHas_Left(false);
return true ;
}

November 15, 2008 at 12:07 AM

// Search for an elemnt in the tree
public int Search(int v_key){
boolean cont ;
int ifound ;
Tree cNode;
int keyValue ;

cNode = this ;
cont = true ;
ifound = 0 ;
while(cont){
keyValue = cNode.GetKey();
if (v_key < keyValue)
if (cNode.GetHas_Left())
cNode = cNode.GetLeft() ;
else cont = false ;
else
if (keyValue < v_key)
if (cNode.GetHas_Right())
cNode = cNode.GetRight() ;
else cont = false ;
else {
ifound = 1 ;
cont = false ;
}
}
return ifound ;
}

// Invoke the method to really print the tree elements
public boolean Print(){
Tree cNode;
boolean bool ;

cNode = this ;
bool = this.RecPrint(cNode);
return true ;
}

// Print the elements of the tree
public boolean RecPrint(Tree node){
boolean bool ;

if (node.GetHas_Left()){
bool = this.RecPrint(node.GetLeft());
} else bool = true ;
System.out.println(node.GetKey());
if (node.GetHas_Right()){
bool = this.RecPrint(node.GetRight());
}
else bool = true ;
return true ;
}
}

----------------------------

Visit for more information.

http://www.roseindia.net/java/

Thanks.

Amardeep









Related Tutorials/Questions & Answers:
B+ tree JAVA source code for implementing Insertion and Deletion - Java Beginners
B+ tree JAVA source code for implementing Insertion and Deletion  Can anyone plz mail de B+ tree JAVA source code for implementing Insertion and Deletion..Its urgent   Hi friend, public class BinarytreeDemo
deletion in b plus tree
deletion in b plus tree  please help me out!! i need a code for deletion on b-plus tree in JAVA. its urgent please help
Advertisements
B+ tree - Java Beginners
several operations on B+-tree.  InsertionDeletion  Update.... In this assignment, you will implement B+-tree data structure on a fixed-length data... field is separated or delimited by a white space. Initially, your B+-tree
Implementing FTP in Java Code
Implementing FTP in Java Code  Hi, My job is to write a program in Java in my project. I have to implement FTP in my Java Code. Share me some of the code of Implementing FTP in Java Code. Thanks   Hi, Apache ftp
Source Code for Implementing Search Feature in JSP using Java action/Servlet - JSP-Servlet
Source Code for Implementing Search Feature in JSP using Java action/Servlet  How do I write the source code to implement search feature in JSP using Java action/servlet? My query is: SELECT @rownum:=@rownum+1 'rownum', X
B+tree lodaing - Java Beginners
B+tree lodaing  hi, i have fixed-length data file such student table. All fields are fixed length: 8 for number (20022509), 3 for name (PIS), 4... or delimited by a white space. how i can Initially, constructed B+ tree based
Source Code for Implementing Search Feature in JSP using Java Action/Servlet - JSP-Interview Questions
Source Code for Implementing Search Feature in JSP using Java Action/Servlet  How do I write the source code to implement search feature in JSP using... searchServlet /search Thanks  I have following your source code
Source Code for Implementing Search Feature in JSF/JSP using Servlet - Java Beginners
Source Code for Implementing Search Feature in JSF/JSP using Servlet  How do I write the source code to implement search feature in JSF/JSP using..., example in jsf, jsp, java method   Hi friend, package javacode
Java source code
Java source code  How are Java source code files named
java source code
java source code  java source code to create mail server using struts2
complete this code (insertion sort) - Java Beginners
complete this code (insertion sort)  Your task is to develop part... to use a modiŻed version of insertion-sort algorithm which works as follows...++; } } return newArray; } }  Hi friend, Code to solve the problem
request for java source code
request for java source code  I need source code for graphical password using cued-click points enabled with sound signature in java and oracle 9i as soon as possible... Plz send to my mail
Creating Database using B+Tree in Java - Java Beginners
Creating Database using B+Tree in Java  I'm doing a project in which I have to create an Object Oriented Database using B+Tree in Java..., Code to help in solving the problem : public class BinarytreeInsert
Java Source code
Java Source Code for text chat application using jsp and servlets  Code for text chat application using jsp and servlets
Source Code - Java Beginners
Source Code  What do I have to add to my original code to make it work
Source Code - Java Beginners
Source Code  How to clear screen on command line coding like cls in DOS?  Hi Friend, Here is the code to execute cls command of DOS through the java file but only one restriction is that it will execute
source code of java
source code of java  how to create an application using applets is front end and back end is sqlwith jdbc application is enter the student details and teaching & non teaching staff details and front end is enter in internet
source code - Java Beginners
source code  Hi...i`m new in java..please help me to write program that stores the following numbers in an array named price: 9.92, 6.32, 12,63... message dialog box.  Hi Friend, Try the following code: import
code for implementing sale purchase
code for implementing sale purchase  i have two tables in database. in one table i have stock of sms and further details and other table is for customer .if customer purchases my sms then the value will be deduct from my table
insertion sort applet code
insertion sort applet code  i need Insertion Sort Applet Program
Binary search tree (insertion) urgent!!
Binary search tree (insertion) urgent!!  Create a program to construct a binary search tree consisting of nodes that each stores an integer in Java.Avoid duplication of values when inserting nodes in the tree. When a new leaf
java source code - Java Beginners
java source code  I have written a source code for recording invoices. I wish it to be evaluated. Could somebody help me with it? Moreover, I do not know the method to attach the JAR for evaluation. My email
Java Source code - Java Beginners
Java Source code  Write a Multi-user chat server and client
source code
source code  how to use nested for to print char in java language?   Hello Friend, Try the following code:ADS_TO_REPLACE_1 class... = { {'A', 'B'}, {'C','D'} }; for (int i=0;i<2;i
source code program - Java Beginners
source code program  I need the source code for a program that converts temperatures from celsius to fahrenheit and vice versa, as well as converting kilometers to miles and vice versa using Java "classes".  Hi
java source code - Java Beginners
java source code  write a program to read the value of n as total number of friend relatives to whom the person wants to call
Need Java Source Code - JDBC
Need Java Source Code  I have a textfield for EmployeeId in which the Id, for eg: "E001" has to be generated automatically when ever i click... be implemented.  Hi friend, Please send me code because your posted
Java source code - Java Beginners
Java source code  Write a small record management application for a school. Tasks will be Add Record, Edit Record, Delete Record, List Records. Each Record contains: Name(max 100 char), Age, Notes(No Maximum Limit). No database
Source Code cls - Java Beginners
Source Code cls   Dear RoseIndia Team, Thanks for your prompt reply to my question about alternate to cls of dos on command line source code. I have two submissions. 1. Instead of three lines if we simply write
Source code
Source code  source code of html to create a user login page
java source code - Java Beginners
java source code  hello Sir, Im a beginner in java.im greatly confused, so plz send me the source code for the following concept: Telephone... code: import java.io.*; import java.util.*; class Directory implements
calendra.css source code - Java Beginners
calendra.css source code  hello i need the source code... and year are getting displayed  Hi Friend, Try the following code...; cursor: pointer; } You can also download the code from the following link
source code
source code  sir...i need an online shopping web application on struts and jdbc....could u pls send me the source code
source code
source code  sir...i need an online shopping web application on struts and jdbc....could u pls send me the source code
source code
source code  hellow!i am developing a web portal in which i need to set dialy,weekly,monthly reminers so please give me source code in jsp
initializing B+ tree from Jtable - JDBC
initializing B+ tree from Jtable   hi, i have fixed-length data file such student table.i stored this file in Jtable All fields are fixed length: 8... i can Initially, constructed B+ tree based from this Jtable. and make initial
source code
source code  how to get the fields from one page to another page in struts by using JSTL
online shopping project report with source code in java
online shopping project report with source code in java  Dear Sir/Mam, i want to a project in java with source code and report project name online shopping. thank you
online voting system source code in java
online voting system source code in java  Please send me source code for online voting system in java. please replay as fast as. Thank you
download java source code for offline referral
download java source code for offline referral   how can i download complete java tutorial from rose india so that i can refer them offline
Screen scrapper tool java source code
Screen scrapper tool java source code  From where can i dload the souce code for this screen scrapper tool ? Please let me know. Thanks
View source code of a html page using java ..
View source code of a html page using java ..  I could find the html source code of a web page using the following program, http://download.oracle.com/javase/1.4.2/docs/api/java/net/URLConnection.html i could get the html code
source code - Java Server Faces Questions
source code  hi deepak i need a program's source code in javascript which will response to mouse event. with description of onmouseout nd onmouseover... waiting 4 ur reply   Hi friend, Code for onmouseout nd
Insertion Sort - Java Beginners
Insertion Sort  Hello rose india java experts.If you don't mind.Can you help me.What is the code for Insertion Sort and Selection Sort that displays....   Hi Friend, Try the following code: 1)InsertionSort.java
Problem with Java Source Code - Java Beginners
Problem with Java Source Code  Dear Sir I have Following Source Code ,But There is Problem with classes, plz Help Me. package mes.gui; import javax.swing.JOptionPane.*; import java.sql.*; import javax.swing.*; import
source code for the following question
source code for the following question  source code for the fuzzy c-means
Java insertion sort question
Java insertion sort question  I've got another program that I need help with. I am trying to write a Java method that accepts an array of strings, and sorts the strings using the insertion sort algorithm. Then I need to write
java source code to create mail server using struts2
java source code to create mail server using struts2  java source code to create mail server using struts2
source code in jsp
source code in jsp  i need the source code for online payment in jsp
i need attendce management system source code in java
i need attendce management system source code in java  i need attendance management system source code in java

Ads