Closed Thread Icon

Topic awaiting preservation: anyone having B-tree code in java ,for searchig and insertion Pages that link to <a href="https://ozoneasylum.com/backlink?for=26763" title="Pages that link to Topic awaiting preservation: anyone having B-tree code in java ,for searchig and insertion" rel="nofollow" >Topic awaiting preservation: anyone having B-tree code in java ,for searchig and insertion\

 
Author Thread
kush
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Sep 2005

posted posted 10-01-2005 08:11

hi,
I am asking all you gurus out there ,does anyone has a B-tree cod in java ,implementing searching and insertion of the order 3 or 4.I need it ASAP ,my job is at stake ,this could save my life.Plz anyone send it on my mail id kushal822003@yahoo.com or post it on this forum.Plz help me outta here.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 10-01-2005 10:31

well, I don't have one at hand, but a simple 'insert & lookup' bstring is easy enough to code...

Now, to make a balanced b-tree, that'd be work ;-)

code:
//bassic element array(key, value, left, right)

function addValue(bTree,key,value)
{
   if (bTree[0] < key)
   {
     if (bTree[2])
         addValue(bTree[2],key,value);
    else
        bTree[2] = new Array(key,value,false,false);
   }
   else
   {
     if (bTree[3])
         addValue(bTree[3],key,value);
    else
        bTree[3] = new Array(key,value,false,false);
   }
}

function search(bTree,key)
{
   if (bTree[0] == key)
     return bTree[1];
   else if (bTree[0] < key)
     return search(bTree[2],key)
  else
   return search(bTree[3],key);
}


usage:
root = new Array("root","I am the very root",false,false);
addValue(root,'test','just a test');
addValue(root,'shu','shuuuuhuhuhuhu');

alert(search(root,'shu'));



so long,

->Tyberius Prime

« BackwardsOnwards »

Show Forum Drop Down Menu