Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Queue-Usage/Kotlin/queue-usage.kotlin
Normal file
22
Task/Queue-Usage/Kotlin/queue-usage.kotlin
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// version 1.1.2
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val q: Queue<Int> = ArrayDeque<Int>()
|
||||
(1..5).forEach { q.add(it) }
|
||||
println(q)
|
||||
println("Size of queue = ${q.size}")
|
||||
print("Removing: ")
|
||||
(1..3).forEach { print("${q.remove()} ") }
|
||||
println("\nRemaining in queue: $q")
|
||||
println("Head element is now ${q.element()}")
|
||||
q.clear()
|
||||
println("After clearing, queue is ${if(q.isEmpty()) "empty" else "not empty"}")
|
||||
try {
|
||||
q.remove()
|
||||
}
|
||||
catch (e: NoSuchElementException) {
|
||||
println("Can't remove elements from an empty queue")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue