Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 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