Topic awaiting preservation: anyone having B-tree code in java ,for searchig and insertion (Page 1 of 1) |
|
---|---|
Neurotic (0) Inmate Newly admitted From: |
posted 10-01-2005 08:11
hi, |
Paranoid (IV) Mad Scientist with Finglongers From: Germany |
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... 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'));
|