<commit_before>package ca.six.algo.tree

import java.util.*
import kotlin.collections.ArrayList

/*
              9
     5                 20
  3     7         15        24
1   4 6   8    12    18  22     28
 */

fun DFS(root: TreeNode) {
    val result = ArrayList<Int>()
    val stack = Stack<TreeNode>()

    stack.push(root)

    while (!stack.isEmpty()) {
        val node = stack.pop()
        result.add(node.data)

        if (node.right != null) {
            stack.push(node.right) //先存右边. 栈是先进后出, 我们要先遍历左树, 所以要先存右树
        }
        if (node.left != null) {
            stack.push(node.left)
        }
    }

    println(result)
}

fun main() {
    DFS(n9)
}<commit_msg>DFS, actually is the inorder iteration<commit_after>package ca.six.algo.tree

import java.util.*
import kotlin.collections.ArrayList

/*
              9
     5                 20
  3     7         15        24
1   4 6   8    12    18  22     28
 */

fun DFS(root: TreeNode) {
    val result = ArrayList<Int>()
    val stack = Stack<TreeNode>()

    stack.push(root)

    while (!stack.isEmpty()) {
        val node = stack.pop()
        result.add(node.data)

        if (node.right != null) {
            stack.push(node.right) //先存右边. 栈是先进后出, 我们要先遍历左树, 所以要先存右树
        }
        if (node.left != null) {
            stack.push(node.left)
        }
    }

    println(result)
}

fun inorder(root: TreeNode?) {
    if(root == null) return

    print("${root.data}, ")
    inorder(root.left)
    inorder(root.right)
}

fun main() {
    DFS(n9)
    inorder(n9)
}
{'fraction_non_alphanumeric': 0.127190136275146, 'fraction_numerical': 0.030499675535366644, 'mean_word_length': 1.6179966044142615, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '529972', 'n_tokens_mistral': 587, 'n_tokens_neox': 572, 'n_words': 121}