3

你能给我一个使用队列和链表的 Groovy 示例应用程序吗?

4

1 回答 1

10

一个队列的例子:

def q = ["elem1", "elem2"] as Queue

q.offer("inserted string")
assert q.peek() == "elem1"
assert q.poll() == "elem1"
assert q.poll() == "elem2"
assert q.poll() == "inserted string"

这是一个带有链表的示例:

def l = [1, 2, 3] as LinkedList
assert l[0] == 1
l.add(4)
assert l.last() == 4
于 2012-04-27T06:44:45.540 回答