z***s 发帖数: 91 | 1 noname 这个class 应该起个什么名字才符合它的功能
class NoName
6 {
7 children = new Hashtable()
8 name = ""
9
10 boolean hasChild(child: string)
11 {
12 return this.children.hasKey(child)
13 }
14
15 NoName addChild(child: string)
16 {
17 var childnode = new NoName()
18 childnode.name = child
19 this.children[child] = childnode
20 return childnode
21 }
22
23 NoName getNode(child: string)
24 {
25 if this.hasChild(child)
26 return this.children[child]
27 else
28 return this.addChild(child)
29 }
30
31 void addList(input: string)
32 {
33 var currentNode = this.getNode(input[0])
34 input = input.SubString(1, input.Length − 1)
35 if (input.Length < 1)
36 currentNode.getNode("")
37 else
38 currentNode.addList(input)
39 }
40
41 string scan()
42 {
43 if (this.children.Values.Length == 0)
44 return this.name
45 if (this.children.Values.Length == 1)
46 return this.name + this.children.Values[0].scan()
47
48 var temp = new Array()
49 foreach(child in this.children.Values)
50 temp.Add(child.scan())
51
52 return this.name + "{" + temp.Sorted().JoinArray(",") + "}"
53 }
54 }
55
56 var x = new NoName()
57 x.addList(’/home/user/foo’)
58 x.addList(’/home/user/bar’)
59 x.addList(’/home/user/baz/one’)
60 x.addList(’/home/user/baz/two’)
61
62 print x.scan() |
y*******g 发帖数: 6599 | |
z***s 发帖数: 91 | 3 不是c,c++,java。 我不知道是什么语言,我猜是c#.
【在 y*******g 的大作中提到】 : 什么语言?
|
f*******t 发帖数: 7549 | 4 用来生成类似于这样的数组字符串:
{ a { b, c } } |
c**y 发帖数: 2282 | 5 也不是,没有分号,很多细节不同
【在 z***s 的大作中提到】 : 不是c,c++,java。 我不知道是什么语言,我猜是c#.
|
z***s 发帖数: 91 | 6 谢谢了! 能不能说得再详细些,除了hashtable,还跟什么数据结构有关。另外,有什
么改进的办法。
【在 f*******t 的大作中提到】 : 用来生成类似于这样的数组字符串: : { a { b, c } }
|
f*******t 发帖数: 7549 | 7 都不知道是用什么语言写的,我前面说的输出只是大致的估计,改进办法什么的还是别
想了……
【在 z***s 的大作中提到】 : 谢谢了! 能不能说得再详细些,除了hashtable,还跟什么数据结构有关。另外,有什 : 么改进的办法。
|