OneCompiler

LinkedList basic Node

151
 fun main(args: Array<String>) {
  val root = Node(1)
  var tail  = root
  for(i in 10..15) {
    val newNode = Node(i)
    tail.nextNode = newNode
    tail = newNode
  }
  root.printAllNodes()
}

class Node(val value : Int, var nextNode : Node ? = null) {
  fun printAllNodes() {
    var currentNode : Node? = this
    while(currentNode != null){
      print("${currentNode.value} ")
      currentNode = currentNode.nextNode
    }
  }

}