请教用递归算法去图像离散点的函数堆栈溢出错误

xionw 2008-03-04 03:13:37
//p:指针数组 (ppbtarray=array [0..999] of pbytearray,存储BMP图像的像素扫描结果
//lplab:二维数组plab=array [0..1999,0..1999] of boolean
//width:bmp.width
//heigh:bmp.heigh
//x,y:当前坐标
//m_lianxushu:连续点计数
//lianxushu:离散点阀值
function DeleteScaterJudge(P:ppbtarray;lplab:plab;width,heigh,x,y,M_lianxushu,lianxushu:Integer):Boolean;
begin
if M_lianxushu>lianxushu then
begin
result:=True;
//lianxushu:=lianxushu+1;
Inc(lianxushu);
lplab[X,Y]:=True;
end;
Result:=False;
if M_lianxushu>lianxushu then
Result:=True
else if (x<width) and (y<heigh) then
//开始进入递归
begin
//下面
if (p[Y+1][x]=0)and not(lplab[Y+1,x]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x,y+1,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=True;
end;
//左面
if (p[y][x-1]=0) and not(lplab[y,x-1]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x-1,y,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
//上面
if (p[y-1][x]=0) and not(lplab[y-1,x]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x,y-1,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
//右面
if (p[y][x+1]=0) and not(lplab[y,x+1]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x+1,y,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
//左上
if (p[y-1][x-1]=0) and not(lplab[y-1,x-1]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x-1,y-1,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
//左下
if (p[y+1][x-1]=0) and not(lplab[y+1,x-1]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x-1,y+1,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
//右上
if (p[y-1][x+1]=0) and not(lplab[y-1,x+1]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x+1,y-1,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
//右下
if (p[y+1][x+1]=0) and not(lplab[y+1,x+1]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x+1,y+1,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
end;
end;

调用函数时出现stack overflow的错误,请高手们指点一下
里面的错误请高手们指点一下,万分感谢
...全文
98 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
knowledge_Is_Life 2008-05-01
  • 打赏
  • 举报
回复
这个简单啊,网上搜一下就得到答案了.
ZuoBaoquan 2008-03-05
  • 打赏
  • 举报
回复
Stack Overflow一般有两个原因:
1. 算法错误
2. 局部变量所占空间过大

你可以先尝试更改一些函数原型:
function DeleteScaterJudge(P:ppbtarray;const lplab: array of array of Boolean;width,heigh,x,y,M_lianxushu,lianxushu:Integer):Boolean;
etomahawk 2008-03-04
  • 打赏
  • 举报
回复
stack overflow 堆栈溢出。
不要用递归就可解决堆栈溢出问题了。 ^_^
默认的栈只有1M/2M(根据编译器设置),不够用的时候当然出现stack overflow了。

要么换个算法,要么就自己模拟堆栈。

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧