Kotlin
import io.klibs.collections.*
fun main() {
// Make a stack from varargs!
val stack = stackOf(1, 2, 3)
// Make a stack from a collection!
val stack = stackOf(listOf(1, 2, 3))
// Make a stack the boring way!
val stack = Stack<Int>()
// Make a stack the crazy way!
val stack = Stack<Int>(
initialCapacity = 16,
scaleFactor = 1.5F,
maxSize = 100
)
// Push stuff onto a stack!
stack.push(3)
stack.push(2)
stack.push(1)
// Pop stuff off of a stack!
stack.pop() // 1
stack.pop() // 2
stack.pop() // 3
// Iterate! (destructively)
for (item in stack)
println("Popped another item off the stack!")
// Iterate! (non-destructively)
for (i in stack.indices)
println("Just peeking at ${stack[i]}!")
}