基于二叉树的思路实现的“十叉树”
该数据结构用于以替代一些简单的本地缓存系统,并提供快速检索的功能。
业务场景:
用户帐号223,拥有下级帐号223001、223002、2230055、22312345...
用户帐号224,拥有下级帐号224002、2248888...
用户...
223和224,我们暂且叫他为大帐号,后面的都叫小帐号。
当这些小帐号发消息给系统时,需要识别出对应的大帐号,且小帐号的长度不等,不可以检索库表。
假设大帐号已经驻留在内存。
java代码:
public static void main(String[] args) { try { BinaryTree bt = new BinaryTree(); String key = "223"; String msg = "hello jason"; bt.insert(key, msg); TreeNode node = bt.search(key); if (node != null) { System.out.println(node.getValue()); } node = bt.search("223001"); if (node != null) { System.out.println(node.getValue()); } System.out.println("Done!"); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }