forked from realpacific/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedListDuplicate.kt
46 lines (39 loc) · 947 Bytes
/
LinkedListDuplicate.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package linkedlists
import kotlin.test.assertFalse
import kotlin.test.assertTrue
fun main() {
val list = LinkedList()
list.addLast(Node(0))
list.addLast(Node(1))
list.addLast(Node(2))
list.addLast(Node(3))
list.addLast(Node(4))
assertFalse(list.hasDuplicates())
list.addLast(Node(1))
list.printAll()
assertTrue(list.hasDuplicates())
list.subListFrom(2).also {
println(it)
assertTrue(it.isNotEmpty())
}
list.subListFrom(100).also {
println(it)
assertTrue(it.isEmpty())
}
list.deleteAt(2).also {
assertTrue(it != null && it.value == 2)
}
list.printAll()
list.deleteAt(100).also {
assertTrue(it == null)
}
list.nodeAt(0).also {
assertTrue(it != null && it.value == 0)
}
println("____REVERSE__")
list.printAll()
list.reverse().also {
print("Reversed: ")
it.printAll()
}
}