h*****g 发帖数: 312 | 1 一家CS公司以前的面试题,看了半天硬是没看懂,能不能帮忙看看这代码输出啥?
谢谢!
1 // *********
2 // SAMPLE #2
3 // *********
4
5 class NoName
6 {
7 children = new Hashtable()
8 name = ""
9
10 boolean haschild(child: string)
11 {
12 return children.contains(child)
13 }
14
15 NoName addChild(child: string)
16 {
17 childnode = new NoName()
18 childnode.name = child
19 children[child] = childnode
20 return childnode
21 }
22
23 NoName getNode(child: string)
24 {
25 if haschild(child)) then return children[child]
2 | b***e 发帖数: 1419 | 2 /home/user/{ba{r, z/{one, two}}, foo}
This program establish a prefix-tree, and print it in a serialized format. |
|