tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
22
Task/Queue-Definition/Groovy/queue-definition-1.groovy
Normal file
22
Task/Queue-Definition/Groovy/queue-definition-1.groovy
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
class Queue {
|
||||
private List buffer
|
||||
|
||||
public Queue(List buffer = new LinkedList()) {
|
||||
assert buffer != null
|
||||
assert buffer.empty
|
||||
this.buffer = buffer
|
||||
}
|
||||
|
||||
def push (def item) { buffer << item }
|
||||
final enqueue = this.&push
|
||||
|
||||
def pop() {
|
||||
if (this.empty) throw new NoSuchElementException('Empty Queue')
|
||||
buffer.remove(0)
|
||||
}
|
||||
final dequeue = this.&pop
|
||||
|
||||
def getEmpty() { buffer.empty }
|
||||
|
||||
String toString() { "Queue:${buffer}" }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue