c++ 获取树结构的深度

struct AA

{

string strName;

vector vecSub;

};

int getRowCount(AA root)

{

queue que;

que.push(root);

int layer = 0;

while (!que.empty())

{

int size = que.size();

while (size)

{

AA aaa = que.front();

que.pop();

for (int i = 0; i < aaa.vecSub.size(); i++)

{

que.push(aaa.vecSub[i]);

}

size--;

}

layer++;

}

return layer;

}

你可能感兴趣的:(c++,c++,树,深度,层次)