for(int i = 0; i <(int)m_pSTreeRoot->Child.size(); i++)
{
if(i ==(int)m_pSTreeRoot->Child.size() - 1)
{
bIsEnd[0] = 1;
}
PrintNode(m_pSTreeRoot->Child[i], 1,bIsEnd);
}
cout << endl;
}
voidCSuffixTree::PrintNode(mynode p, int c, vector
{
for(int j=0; j
{
if(isend[j] == 0)
{
if(j != c-1)
cout << "│";
else
cout << "├";
}
else
{
if(j != c-1)
cout << " ";
else
cout << "└";
if(j != c-1)
cout << " ";
else
cout <<""; //最后一個
}
}
cout << " " <
//if(p->Child.size() == 0)cout <<" (" << p->nIndex << ")";
cout << endl;
for(int i=0; i<(int)p->Child.size();i++)
{
if(isend.size() == c)
{
isend.push_back(0);
}
else
{
isend[c]=0;
}
if(i == (int)p->Child.size() - 1)
{
if(isend.size() == c)
isend.push_back(1);
else
isend[c]=1;
}
PrintNode(p->Child[i], c + 1,isend);
}
}
//mian.cpp
intmain(int argc, char* argv[])
{
string a;
cout << "Please input astring:";
cin >> a; //通過輸入獲得目標字符串a(chǎn)
CSuffixTree mytree(a); //產(chǎn)生CsuffixTree類的實例mytree
mytree.CreatTree(); //調(diào)用CreatTree方法創(chuàng)建一棵后綴樹
mytree.Show(mytree.ST); //調(diào)用Show方法輸出生成的后綴樹
}
相關(guān)推薦:北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內(nèi)蒙古 |