can any one explain boundry fill c program recursive function call's ?
hi friend's,
i want to know about how the recursive call are made in program given below .(the program is running properly )
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void fillcolor(int,int,int,int);
void main()
{
int gdriver=DETECT,gmode;
int xc,yc,r,fc,bc;
clrscr();
initgraph(&gdriver,&gmode,"f:\\tc\\bgi");
printf("enter center & radius : ");
scanf("%d %d %d",&xc,&yc,&r);
printf("enter boundry & fill color : ");
scanf("%d %d",&bc,&fc);
setcolor(bc);
circle(xc,yc,r);
fillcolor(xc,yc,bc,fc);
getch();
}
void fillcolor(int x,int y,int bc,int fc)
{
int cp;
cp=getpixel(x,y);
if(cp!=bc && cp!=fc)
{
delay(20);
putpixel(x,y,fc);
fillcolor(x+1,y,bc,fc);
fillcolor(x-1,y,bc,fc);
fillcolor(x,y+1,bc,fc);
fillcolor(x,y-1,bc,fc);
}
}
my problem is that i think that when the function is called first time
then the recursive call fillcolor(x+1,y,bc,fc) will proceed in x direction and when boundry is reaches than the if(cp!=bc && cp!=fc) condition will be false and the control should return to main .
But it is not happening like this so can any one explain this recursive calls to me .
pls reply soon .
i want to know about how the recursive call are made in program given below .(the program is running properly )
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void fillcolor(int,int,int,int);
void main()
{
int gdriver=DETECT,gmode;
int xc,yc,r,fc,bc;
clrscr();
initgraph(&gdriver,&gmode,"f:\\tc\\bgi");
printf("enter center & radius : ");
scanf("%d %d %d",&xc,&yc,&r);
printf("enter boundry & fill color : ");
scanf("%d %d",&bc,&fc);
setcolor(bc);
circle(xc,yc,r);
fillcolor(xc,yc,bc,fc);
getch();
}
void fillcolor(int x,int y,int bc,int fc)
{
int cp;
cp=getpixel(x,y);
if(cp!=bc && cp!=fc)
{
delay(20);
putpixel(x,y,fc);
fillcolor(x+1,y,bc,fc);
fillcolor(x-1,y,bc,fc);
fillcolor(x,y+1,bc,fc);
fillcolor(x,y-1,bc,fc);
}
}
my problem is that i think that when the function is called first time
then the recursive call fillcolor(x+1,y,bc,fc) will proceed in x direction and when boundry is reaches than the if(cp!=bc && cp!=fc) condition will be false and the control should return to main .
But it is not happening like this so can any one explain this recursive calls to me .
pls reply soon .
0