class TreeMap {
TreeMapNode topNode = null;
public void add(Comparable key, Object value) {
if(topNode == null)
topNode= new TreeMapNode(key, value);
else
topNode.add (key, value);
}
public Object get(Comparable key) {
return topNode == null ? null : topNode.find (key) ;
}
}
class TreeMapNode {
private final static int LESS = 0;
private final static int GREATER = 1;
private Comparable itsKey;
private Object itsValue;
private TreeMapNode nodes[] = new TreeMapNode[2];
public TreeMapNode (Comparable key, Object value) {
itsKey = key;
itsValue = value;
}
public Object find(Comparable key) {
if (key. compareTo(itsKey) == 0)
return itsValue;
else System.out.println(itsValue);
return findSubNodeForKey (selectSubNode (key) , key) ;
}
private int selectSubNode(Comparable key) {
return (key. compareTo(itsKey) < 0) ? LESS : GREATER;
}
private Object findSubNodeForKey(int node, Comparable key) {
return nodes[node] == null ? null : nodes[node].find (key);
}
public void add(Comparable key, Object value) {
if (key. compareTo(itsKey) == 0)
itsValue = value;
else
addSubNode (selectSubNode (key), key, value);
}
private void addSubNode(int node, Comparable key, Object value) {
if (nodes[node] == null)
nodes[node] = new TreeMapNode(key, value) ;
else
nodes[node] .add(key, value);
}
}
public class TreeMapApp {
public static void main(String[] args) {
TreeMap names=new TreeMap();
names.add("martin","martin");
names.add("bob","bob");
names.add("robin","robin");
names.add("alan","alan");
names.add("don","don");
names.add("paul","paul");
names.add("sam","sam");
String result=(String) names.get("martin");
System.out.println(result);
}
}
여기서 노드를 다 출력하게 할려면 도대체 어떻게 해야댐?? 코린이 좀 살려줘
제에발 알려줘 이러다간 다 죽어~~ 추가한 노드들을 다 출력할려면 어떻게 해야할까.. 아무리 생각해도 모르겠어
이게 무슨 언어인가요 ㅇㅅㅇ
모르는척ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
알려드렸습니다^^ - dc App
상위 1퍼 순회
이시발롬들아 너네도 모르지