Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void count(Node *root) {
- static bool b = false;
- if(root == nullptr)
- {
- cout<<0;
- return;
- }
- queue<Node*> q;
- q.push(root);
- cout<<1;
- int nodesOnLevel = 1;
- int currentLevel = 0;
- while(!q.empty())
- {
- Node* current = q.front();
- q.pop();
- nodesOnLevel--;
- if(current->leftNode!=nullptr)
- {
- q.push(current->leftNode);
- }
- if(current->rightNode!=nullptr)
- {
- q.push(current->rightNode);
- }
- if(nodesOnLevel==0)
- {
- nodesOnLevel = q.size();
- if(nodesOnLevel!=0)
- { cout<<";"<<nodesOnLevel;
- }
- currentLevel++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement