Queue/Definition: Difference between revisions

→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details
(Added Algol W)
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 2,331:
 
=={{header|Kotlin}}==
<lang scala>// version 1.1.12
 
import java.util.LinkedList
Line 2,341:
 
val empty get() = size == 0
 
fun push(element: E) = data.add(element)
 
fun pop(): E {
if (empty) throw RuntimeException("Can't pop elements from an empty queue")
return data.removeFirst()
}
 
val top: E
get() {
if (empty) throw RuntimeException("Empty queue can't have a top element")
return data.first()
}
Line 2,365:
println(q)
println("Size of queue = ${q.size}")
print("Popping: ")
(1..3).forEach { print("${q.pop()} ") }
println("\nRemaining in queue: $q")