Algorithm 搜索关闭标记的算法

Algorithm 搜索关闭标记的算法,algorithm,Algorithm,最好给我举个例子(任何语言)这样做的传统方法是使用堆栈。当你得到一个打开的标签时推,当你得到一个关闭的标签时拉。从空堆栈中提取或在末尾具有非零堆栈表示标记不匹配。传统的方法是使用堆栈。当你得到一个打开的标签时推,当你得到一个关闭的标签时拉。从空堆栈中提取或在末尾具有非零堆栈表示标记不匹配。伪代码 input: lineopen (line having opening tag) input: text (test as array of lines) output: linecl



最好给我举个例子(任何语言)

这样做的传统方法是使用堆栈。当你得到一个打开的标签时推,当你得到一个关闭的标签时拉。从空堆栈中提取或在末尾具有非零堆栈表示标记不匹配。

传统的方法是使用堆栈。当你得到一个打开的标签时推,当你得到一个关闭的标签时拉。从空堆栈中提取或在末尾具有非零堆栈表示标记不匹配。

伪代码

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
伪码

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
简单包含计数器(在开始标记时增加,在结束标记时减少)在作者想要检查标记奇偶性之前就足够了。简单包含计数器(在开始标记时增加,在结束标记时减少)在作者想要检查标记奇偶性之前就足够了。