vovnit

Stack on Kotlin

Feb 24th, 2018
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.34 KB | None | 0 0
  1. class Stack<T>(private val value: T){
  2.     class Node<T>(val value: T, val prev: Node<T>? = null)
  3.     private var head: Node<T>?
  4.     init {
  5.         head = Node(value)
  6.     }
  7.     fun push(value: T) {
  8.         head = Node(value, head)
  9.     }
  10.     fun pop():T? {
  11.         val tmp = head
  12.         head = head?.prev
  13.         return tmp?.value
  14.     }
  15. }
Add Comment
Please, Sign In to add comment