> For the complete documentation index, see [llms.txt](https://soumyajit4419.gitbook.io/ds-algo/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://soumyajit4419.gitbook.io/ds-algo/binary-tree/tree-traversals/level-order-traversal.md).

# 4.Level-order Traversal

Traversing Level by level

Level-order traversal is to traverse the tree level by level.

## Level order traversal using queue

```cpp
class Solution
{
public:
    vector<vector<int>> levelOrder(TreeNode *root)
    {
        vector<vector<int>> vect;
        if (root == NULL)
        {
            return vect;
        }
        queue<TreeNode *> q;
        TreeNode *t = NULL;
        q.push(root);
        vector<int> v;

        while (!q.empty())
        {
            int s = q.size();
             vector<int> v;
            while (s > 0)
            {
                t = q.front();
                q.pop();
                v.push_back(t->val);
                
                if (t->left)
                {
                    q.push(t->left);
                }
                if (t->right)
                {
                    q.push(t->right);
                }
                s--;
            }
            if(v.size()!=0){
              vect.push_back(v);
            }
        }
        return vect;
    }
};
```
