0
Image http://img534.imageshack.us/img534/8542/aaagla.jpg
這是好事,給我一個例子(任何語言)算法搜索關閉標籤
Image http://img534.imageshack.us/img534/8542/aaagla.jpg
這是好事,給我一個例子(任何語言)算法搜索關閉標籤
僞
input: lineopen (line having opening tag)
input: text (test as array of lines)
output: lineclose (line having closing tag)
line := lineopen
counter := 1
do
line := line + 1
if text[line] contains opening tag
then counter := counter + 1
if text[line] contains closing tag
then counter := counter - 1
while counter > 0
lineclose := line
傳統的方式做,這是一個堆棧。當你得到一個開放標籤時推,當你得到一個關閉標籤時拉。從空堆棧拖出或在末尾有非零堆棧表示不匹配的標籤。直到筆者要檢查標籤校驗
簡單列入計數器(增加它在打開的標籤,在收盤減少)就足夠了。 – Vovanium 2010-11-13 17:37:27