tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
46
Task/Queue-Usage/Groovy/queue-usage-2.groovy
Normal file
46
Task/Queue-Usage/Groovy/queue-usage-2.groovy
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
assert q.empty
|
||||
println q
|
||||
// "push" adds to end of "queue" list
|
||||
q.push('Stuart')
|
||||
println q
|
||||
assert !q.empty
|
||||
// "add" adds to end of "queue" list
|
||||
q.add('Pete')
|
||||
println q
|
||||
assert !q.empty
|
||||
// left shift operator ("<<") adds to end of "queue" list
|
||||
q << 'John'
|
||||
println q
|
||||
assert !q.empty
|
||||
// add assignment ("+=") adds the list elements
|
||||
// to the end of the "queue" list in list order
|
||||
q += ['Paul', 'George']
|
||||
println q
|
||||
assert !q.empty
|
||||
// "poll" removes and returns the first element in the
|
||||
// "queue" list ("pop" exists for Groovy lists, but it
|
||||
// removes and returns the LAST element for "Stack"
|
||||
// semantics). "poll" only exists in objects that
|
||||
// implement java.util.Queue, like java.util.LinkedList
|
||||
assert q.poll() == 'Stuart'
|
||||
println q
|
||||
assert !q.empty
|
||||
assert q.poll() == 'Pete'
|
||||
println q
|
||||
assert !q.empty
|
||||
q << 'Ringo'
|
||||
println q
|
||||
assert !q.empty
|
||||
assert q.poll() == 'John'
|
||||
println q
|
||||
assert !q.empty
|
||||
assert q.poll() == 'Paul'
|
||||
println q
|
||||
assert !q.empty
|
||||
assert q.poll() == 'George'
|
||||
println q
|
||||
assert !q.empty
|
||||
assert q.poll() == 'Ringo'
|
||||
println q
|
||||
assert q.empty
|
||||
assert q.poll() == null
|
||||
Loading…
Add table
Add a link
Reference in a new issue