fun main() {
val list = LinkedList()
list.add("Hello")
println(list)
list.add("World")
println(list)
list.add("I am here")
println(list)
// for (i in 0..list.size()){
// println(list.get(i))
// }
// StringBuilderTest.run()
}
class LinkedList {
private var head: Node? = null
private var tail: Node? = null
fun add(value: String) {
if (head == null) {
head = Node(value, null)
tail = head
} else {
tail?.next = Node(value, null)
tail = tail?.next
}
}
}
data class Node(
val value: String,
var next: Node?
)
LinkedList
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.