Home arrow static arrow Java Programming [Archive] - Doubly Linked BST??!!
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Doubly Linked BST??!!
This topic has 2 replies on 1 page.

Registered: 7/13/04
Doubly Linked BST??!!  
Jul 15, 2004 7:35 PM


I am curious to know if it is possible to create a bst that keeps a series of numbers and a series of strings in order at one time?

if that's possible can anyone tell me how to get started on that



Registered: 21.03.00
Re: Doubly Linked BST??!!  
Jul 16, 2004 12:08 AM (reply 1 of 2)


Are the numbers and strings totally unrelated?


Registered: 5/5/04
Re: Doubly Linked BST??!!  
Jul 16, 2004 2:56 AM (reply 2 of 2)

A BST must have a means of comparison to work.
You can use a TreeMap where the key is sortable and refers to the String/Number
    public class MyBST {        private final Map data = new TreeMap();         public MyBST() { }         private Object createKey(Object key) {            return key + "--" + key.getClass();        }        public void put(Object key, Object value) {            data.put(createKey(key), value);        }         public Object get(Object key) {            return data.get(createKey(key).getClass());        }         public int size() {            return data.size();        }         public String toString() {            return data.toString();        }         public static void main(String[] args) {            MyBST mybst = new MyBST();            Number value1 = new Integer(1);            mybst.put(value1, value1);            String textA = "A";            mybst.put(textA, textA);            Number value10 = new BigDecimal("10");            mybst.put(value10, value10);            // not the same as the previous one.            String text10 = "10";            mybst.put(text10, text10);            if (mybst.size() != 4)                System.err.println("Invalid BST");            System.out.println("mybst=" + mybst);        }    }
This topic has 2 replies on 1 page.