I don't think it is correct the for loop looks a little strange. If you don't want to do it recursively and breadth first I would save the depth in the queue along with the node.
int maxDepth(TreeNode *root){
int depth=0;
queue<pair<TreeNode*, int> > ns;
pair<TreeNode*, int> curr;
if (root){
ns.push(make_pair(root, 1));
while (!ns.empty()){
curr = ns.front();
depth = max(depth, curr.second);
if (curr.first->left)
ns.push(make_pair(curr.first->left, curr.second+1));
if (curr.first->right)
ns.push(make_pair(curr.first->right,curr.second+1));
ns.pop();
}//endwhile
}//endif
return depth;
}
Edit: Another way would be to use the code you got but not using ns.size() in the for loop, this will grow or shrink as you add and remove nodes in the queue and you will not traverse a single depth. Instead you need to save ns.size() before you enter the for loop so you only traverse a single depth of the tree each time you enter the for loop.