switch (n)
{
case (-1)://分裂節(jié)點(diǎn),父分裂點(diǎn)為point->breakpoint
tempuse =point->strdata;
cnode=(mynode) new node;
if (point->Child.size() !=0)
{
cnode->Child =point->Child;
}
cnode->flag =point->flag;
point->Child.erase(point->Child.begin(),point->Child.end());
point->strdata.erase(point->strdata.begin(),point->strdata.end());
for (h = 0; h<(point->breakpoint); h++)
{
point->strdata.insert(point->strdata.end(),tempuse[h]);
}
for (h =(point->breakpoint); h { cnode->strdata.insert(cnode->strdata.end(), tempuse[h]); } point->Child.push_back(cnode); cnode = (mynode) new node; cnode->strdata = left; cnode->flag = 0; point->Child.push_back(cnode); point->flag = 1; break; case (0)://do nothing break; case (1)://在葉節(jié)點(diǎn)point處追加left字符串 point->strdata =point->strdata+left; break; case (2)://在父節(jié)點(diǎn)point下添加子節(jié)點(diǎn)cnode cnode = (mynode) new node; cnode->strdata = left; cnode->flag = 0; point->Child.push_back(cnode); point->flag = 1; break; } } } } //返回1: 則在指針point所指向的節(jié)點(diǎn)的strdata后追加 left字符串 //返回2: 則生成point所指向的節(jié)點(diǎn)的子節(jié)點(diǎn),子節(jié)點(diǎn)的strdata值為left字符串 //返回0: 則donothing //返回-1:則分裂節(jié)點(diǎn)將分裂點(diǎn)寫入point指針?biāo)赶虻?節(jié)點(diǎn)的breakpoint,并將目標(biāo)字符串的剩余字符串寫入left intCSuffixTree::Search(string str) { stack int i, n = 0; mynode child; char target; point = ST; //初始搜索位置為根 child = NULL; for (i = (str.length()-1); i >= 0; i--)//將目標(biāo)字符串str壓棧 { s.push(str[i]); } while(!s.empty())//直到搜索完str串 { //尋找point所指向的節(jié)點(diǎn)下與str首字母相同的子節(jié)點(diǎn) for (i = 0; i <=(point->Child.size()-1); i++) { if(point->Child[i]->strdata[0] == s.top()) { child =point->Child[i]; //child指針指向與str具有相同首字母的節(jié)點(diǎn) break; } }
北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內(nèi)蒙古 |