bfs + selection sort
Code
# Code
```golang []
/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func minimumOperations(root *TreeNode) int {
    queues := []*TreeNode{}
    queues = append(queues, root)
    times := 0

    for len(queues) > 0 {
        length := len(queues)
        tempGroup := []int{}
        for i:=0; i<length; i++ {
            current := queues[0]
            queues = queues[1:]
            tempGroup = append(tempGroup, current.Val)
            if current.Left != nil {
                queues = append(queues, current.Left)
            }
            if current.Right != nil {
                queues = append(queues, current.Right)
            }
        }

        L := 0
        for L < len(tempGroup) {
            currentMinIndex := L
            for R:=L+1; R < len(tempGroup); R++ {
                if tempGroup[R] < tempGroup[currentMinIndex] {
                    currentMinIndex = R
                }
            }

            if currentMinIndex != L {
                times++
                tempGroup[currentMinIndex], tempGroup[L] = tempGroup[L], tempGroup[currentMinIndex]
            }
            L++
        } 

    }

    return times
}
```
['Go']