区域填充算法#include""#include""/*forinitgr()*/#include""/*forNULL*/#defineclosegrclosegraphvoidinitgr(void)/*BGI初始化*/{intgd=DETECT,gm=0;/*和gd=VGA,gm=VGAHI是同样效果*/registerbgidriver(EGAVGA_driver);/**/initgraph(&gd,&gm,"");}enumBOOL{FALSE=0,TRUE=1};typedefstruct{inty;intxLeft;intxRight;}Span;/*区段*/typedefstructstacknode{Spanspan;structstacknode*next;}stacknode;typedefstruct{stacknode*top;}linkstack;/*-----------------进栈操作----------------------------------------*/voidPushStack(linkstack*s,Span*span){stacknode*p=(stacknode*)malloc(sizeof(stacknode));p->=span->y;p->=span->xLeft;p->=span->xRight;p->next=s->top;s->top=p;}/*-----------------出栈操作------------------------------------------*/voidPopStack(linkstack*s,Span*span){intx;stacknode*p=s->top;span->y=p->;span->xLeft=p->;span->xRight=p->;s->top=p->next;free(p);}/*-----------------将栈清空------------------------------------------*/voidSetStackEmpty(linkstack*s){stacknode*p=s->top;while(s->top!=NULL){free(p);s->top=p->next;}}/*--------------判断栈是否为空----------------------------------------*/intIsStackEmpty(linkstack*s){if(s->top==NULL)return1;elsereturn0;}/*----------------核心程序开始----------------------------------------*/voidScanLineFill4(intx,inty,intoldColor,intnewColor){intxLeft,xRight;inti;enumBOOLisLeftEndSet,spanNeedFill;Spanspan;linkstack*
区域填充算法 来自淘豆网www.taodocs.com转载请标明出处.