Go BFS
Code

# Code
```golang []
func minimumOperations(root *TreeNode) int {
	totalSwap := 0
	levelValues := make([]int, 0, 8)
	qu := NewQueue()
	qu.Push(root)

	for qu.Size() > 0 {
		levelValues = levelValues[:0]

		for qsize := qu.Size(); qsize > 0; qsize-- {
			node := qu.Pop()
			levelValues = append(levelValues, node.Val)

			if node.Left != nil {
				qu.Push(node.Left)
			}
			if node.Right != nil {
				qu.Push(node.Right)
			}
		}

		totalSwap += getMinSwap(levelValues)
	}

	return totalSwap
}

func getMinSwap(nums []int) int {
	swaps := 0
	sortedNums := make([]int, len(nums))
	copy(sortedNums, nums)
	sort.Ints(sortedNums)

	pos := make(map[int]int, len(nums))
	for i, v := range nums {
		pos[v] = i
	}

	for i, v := range nums {
		if nums[i] != sortedNums[i] {
			swaps++

			needPos := pos[sortedNums[i]]
			pos[v] = needPos
			nums[i], nums[needPos] = nums[needPos], nums[i]
		}
	}

	return swaps
}

type queue struct {
	data []*TreeNode
}

func NewQueue() *queue {
	return &queue{}
}

func (q *queue) Size() int {
	return len(q.data)
}

func (q *queue) Pop() *TreeNode {
	v := q.data[0]
	q.data = q.data[1:]
	return v
}

func (q *queue) Push(v *TreeNode) {
	q.data = append(q.data, v)
}

```
['Tree', 'Breadth-First Search', 'Binary Tree', 'Go']