Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Stack<T>(private val value: T){
- class Node<T>(val value: T, val prev: Node<T>? = null)
- private var head: Node<T>?
- init {
- head = Node(value)
- }
- fun push(value: T) {
- head = Node(value, head)
- }
- fun pop():T? {
- val tmp = head
- head = head?.prev
- return tmp?.value
- }
- }
Add Comment
Please, Sign In to add comment