using map || simple tree printing approach 
Code
# Code
```cpp []
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    int minimumOperations(TreeNode* root) {
        int swaps=0;
        queue<TreeNode*>q;
        q.push(root);
        q.push(NULL);
        vector<int>arr;
        while(!q.empty()){
         auto tope=q.front();
         q.pop();
         if(tope==NULL){
            map<int,int>mp;
            for(int i=0;i<arr.size();i++) mp.insert(make_pair(arr[i],i));
            vector<int>newarr(arr.size(),0);
            int i=0;
            for(auto &x:mp) newarr[x.second]=i++;
            // for(auto x:newarr) cout<<x<<" ";
            // cout<<endl;
            for( i=0;i<newarr.size();i++){
                while(newarr[i]!=i){
                 swap(newarr[i],newarr[newarr[i]]);
                 swaps++;
                }
            }
            arr.clear();
            if(!q.empty()) q.push(NULL);
         }
         else{
            if(tope->left) {
                 arr.push_back(tope->left->val);
                q.push(tope->left);
            }
            if(tope->right){
                arr.push_back(tope->right->val);
                q.push(tope->right);
            } 
         }
        }
        return swaps;
    }
};
```
['Tree', 'Breadth-First Search', 'Binary Tree', 'C++']