mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
WIP new UI elem
This commit is contained in:
28
src/net/torvald/terrarum/QNDTreeNode.kt
Normal file
28
src/net/torvald/terrarum/QNDTreeNode.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
class QNDTreeNode<T>(var data: T? = null, var parent: QNDTreeNode<T>? = null) {
|
||||
var children = ArrayList<QNDTreeNode<T>>()
|
||||
|
||||
|
||||
private fun traverse1(node: QNDTreeNode<T>, action: (QNDTreeNode<T>, Int) -> Unit, depth: Int = 0) {
|
||||
//if (node == null) return
|
||||
action(node, depth)
|
||||
node.children.forEach { traverse1(it, action, depth + 1) }
|
||||
}
|
||||
|
||||
private fun traverse2(node: QNDTreeNode<T>, action: (QNDTreeNode<T>, Int) -> Unit, depth: Int = 0) {
|
||||
//if (node == null) return
|
||||
node.children.forEach { traverse2(it, action, depth + 1) }
|
||||
action(node, depth)
|
||||
}
|
||||
|
||||
fun traversePreorder(action: (QNDTreeNode<T>, Int) -> Unit) {
|
||||
this.traverse1(this, action)
|
||||
}
|
||||
|
||||
fun traversePostorder(action: (QNDTreeNode<T>, Int) -> Unit) {
|
||||
this.traverse2(this, action)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user