repeat{选择节点数较少且队列未空、未满的方向先扩展}if (tail[0]<=tail[1]) andnot((head[0]>=tail[0])or(tail[0]>=maxn)) then expand(0);
if (tail[1]<=tail[0]) andnot((head[1]>=tail[1])or(tail[1]>=maxn)) then expand(1);
{如果一方搜索终止,继续另一方的搜索,直到两个方向都终止}ifnot((head[0]>=tail[0])or(tail[0]>=maxn)) then expand(0);
ifnot((head[1]>=tail[1])or(tail[1]>=maxn)) then expand(1);
Until ((head[0]>=tail[0])or(tail[0]>=maxn)) And ((head[1]>=tail[1])or(tail[1]>=maxn))
折叠expand(st:0..1)程序代码如下:
inc(head[st]);
{取出队列当前待扩展的结点c[st,head[st]]}
for i:=1 to maxk do
begin
if tail[st]>=maxn then exit;
inc(tail[st]);
{产生新结点}
check(st);{检查新节点是否重复}
end;
折叠check(st:0..1)程序代码:
for i:=1 to tail[st]-1 do
if c[st,tail[st]]^.*=c[st,i]^.* thenbegin dec(tail[st]);exit end;
bool(st);{如果节点不重复,再判断是否到达目标状态}
折叠bool(st:0..1)程序代码:
for i:=1 to tail[1-st] do
if c[st,tail[st]]^.*=c[1-st,i]^.* then print(st,tail[st],i);
{如果双向搜索相遇(即得到同一节点),则输出结果}
折叠print(st,tail,k)程序代码:
if st=0 then begin print0(tail);print1(k) end;
else begin print0(k);print1(tail) end;
折叠print0(m)程序代码:
if m<>0thenbegin print(c[0,m]^.f);输出c[0,m]^.* end;
{输出正方向上产生的结点}
折叠print1(m)程序代码
n:=c[1,m]^.f
while m<>0
begin
输出c[1,n]^.*;n:=c[1,n]^.f;
end
{输出反方向上产生的结点}