[C++] Easy Level order traversal
\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0)
```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n\n    int minSwaps(vector<int>arr, int n)\n    {\n        // Create an array of\n        // pairs where first\n        // element is array element\n        // and second element\n        // is position of first element\n        pair<int, int> arrPos[n];\n        for (int i = 0; i < n; i++)\n        {\n            arrPos[i].first = arr[i];\n            arrPos[i].second = i;\n        }\n\n        // Sort the array by array\n        // element values to\n        // get right position of\n        // every element as second\n        // element of pair.\n        sort(arrPos, arrPos + n);\n\n        // To keep track of visited elements.\n        // Initialize\n        // all elements as not visited or false.\n        vector<bool> vis(n, false);\n\n        // Initialize result\n        int ans = 0;\n\n        // Traverse array elements\n        for (int i = 0; i < n; i++)\n        {\n            // already swapped and corrected or\n            // already present at correct pos\n            if (vis[i] || arrPos[i].second == i)\n                continue;\n\n            // find out the number of node in\n            // this cycle and add in ans\n            int cycle_size = 0;\n            int j = i;\n            while (!vis[j])\n            {\n                vis[j] = 1;\n\n                // move to next node\n                j = arrPos[j].second;\n                cycle_size++;\n            }\n\n            // Update answer by adding current cycle.\n            if (cycle_size > 0)\n            {\n                ans += (cycle_size - 1);\n            }\n        }\n\n        // Return result\n        return ans;\n    }\n\n    int minimumOperations(TreeNode* root) {\n        if(!root){\n            return 0;\n        }\n        int cnt=0;\n        queue<TreeNode*> q;\n        q.push(root);\n        int len;\n        while(!q.empty()){\n            vector<int> v;\n            len=q.size();\n            for(int i=0;i<len;i++){\n                TreeNode* temp=q.front();\n                q.pop();\n                v.push_back(temp->val);\n                if(temp->left) q.push(temp->left);\n                if(temp->right) q.push(temp->right);\n            }\n            cnt+=minSwaps(v,v.size());\n        }\n        \n        return\xA0cnt;\n\xA0\xA0\xA0\xA0}\n};\n```
['Breadth-First Search', 'C']