struct ST_NODE
{
wstring wstrParentNode;
wstring wstrChildNode;
wstring wstrNodeName;
};
struct ST_MENU
{
wstring wstrNodeId;
wstring wstrNodeName;
};
vector<vector<wstring>> vctData;
stack<wstring> majorStack; // 主栈
stack<ST_NODE> minorStack; // 副栈
wstring wstrMajorNode = L"";
bool bIsRtn = false;
vector<ST_MENU> vctNode;
for (size_t i = 0; i < vctData.size(); ++i)
{
ST_NODE stNode;
stNode.wstrChildNode = vctData[i][0];
stNode.wstrParentNode = vctData[i][1];
stNode.wstrNodeName = vctData[i][2];
minorStack.push(stNode);
vctNode.clear();
while (!minorStack.empty())
{
stNode = minorStack.top();
minorStack.pop(); // 出副栈
majorStack.push(stNode.wstrChildNode); // 入主栈
ST_MENU stMenu;
stMenu.wstrNodeId = stNode.wstrChildNode;
stMenu.wstrNodeName = stNode.wstrNodeName;
vctNode.push_back(stMenu);
//
// ******
//
bIsRtn = false;
do
{
bool bIsFind = false;
ST_NODE stMinorNode;
if (majorStack.empty())
{
break;
}
wstrMajorNode = majorStack.top();
if (!minorStack.empty())
{
stMinorNode = minorStack.top();
if (wstrMajorNode == stMinorNode.wstrParentNode)
{
bIsFind = true;
}
}
if (!bIsFind)
{
majorStack.pop();
vctNode.pop_back();
}
else
{
bIsRtn = true;
}
} while (!bIsRtn);
}
}
|