1class Node{
2public:
3 long val = 0;
4 Node *left = nullptr, *right = nullptr;
5 Node(int val_): val(val_){}
6};
7
8void level_order_traversal(Node *root=nullptr){
9 // printf("Level Order Tree Traversal: \n");
10 if(not root) return;
11
12 queue<Node*> Q;
13 Q.push(root);
14 Q.push(nullptr);
15
16 while(Q.size() > 1){
17 Node *current = Q.front();
18 Q.pop();
19
20 if(not current){
21 printf("\n");
22 Q.push(nullptr);
23 continue;
24 }
25 printf("%ld ", current->val);
26
27 if(current->left) Q.push(current->left);
28 if(current->right) Q.push(current->right);
29 }
30
31 printf("\n\n");
32}