Day 23: BST Level-Order Traversal

  • + 0 comments

    C++

    void levelOrder(Node * root){
    	//Write your code here
    	queue<Node*> q;
    	if(root != NULL){
    		q.push(root);
    		while(q.size()){
    			cout << q.front()->data << " ";
    			if(q.front()->left != NULL)
    				q.push(q.front()->left);
    			if(q.front()->right != NULL)
    				q.push(q.front()->right);
    			q.pop();
    		}
    	}
    }