473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

how does the recursion in the code is actually working

Siddarth777
heres a code for boundary filling
my doubt is how the control is going from one fill_right function to other
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<graphics.h>
  4. #include<dos.h>
  5.  
  6. void fill_right(x,y)
  7. int x , y ;
  8. {
  9. if((getpixel(x,y) != WHITE)&&(getpixel(x,y) != RED))
  10. {
  11. putpixel(x,y,RED);
  12. fill_right(++x,y);
  13. delay(1);
  14. x = x - 1 ;
  15. fill_right(x,y-1);
  16. fill_right(x,y+1);
  17. }
  18. delay(1);
  19. }
  20.  
  21.  
  22. void fill_left(x,y)
  23. int x , y ;
  24. {
  25. if((getpixel(x,y) != WHITE)&&(getpixel(x,y) != RED))
  26. {
  27. putpixel(x,y,RED);
  28.  
  29. fill_left(--x,y);
  30. x = x + 1 ;
  31. fill_left(x,y-1);
  32. fill_left(x,y+1);
  33. }
  34. delay(1);
  35. }
  36.  
  37.  
  38. void main()
  39. {
  40. int x,y,n,i;
  41. int gd=DETECT,gm;
  42. clrscr();
  43.  
  44. initgraph(&gd,&gm,"c:\\tc\\bgi");
  45.  
  46.  
  47.  
  48. /*- draw object -*/
  49.  
  50. line (50,50,200,50);
  51. line (200,50,200,100);
  52. line (200,100,50,100);
  53. line (50,100,50,50);
  54.  
  55. /*- set seed point -*/
  56. x = 125; y = 75;
  57.  
  58. fill_right(x,y);
  59. fill_left(x-1,y);
  60.  
  61. getch();
  62. }
  63.  
  64.  
please help me......thanks a lot
Oct 18 '10 #1
1 1217
weaknessforcats
9,208 Expert Mod 8TB
The wasiest way to see how recursion works is to use Post-It sheets.

When you call the fill function, take a Post-It and write down the names and values of the variables.

Next, go through the code a line at a time and make chnages to the variables based on the code.

When you get to a call to the fill function inside the fill function, stop writing on the Post-It and start a new one for the new call.

Now go back to the start of the fill function and write doiwn the values as you did before but these will be the values from the second call.

Step through the code again and if you get to another call to the fill function start another Post-It.

When you finally get to a return in the fill function, you go back to the previous Post-It and resume stepping through the fill function after the place where it was called.

Eventually, you will work your way back to main().
Oct 18 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tersia Ehlert | last post by:
Hi I have an .NET web application where I redirect a page on submit to a blank page where the code below runs client side. I want to, with this code, refresh two frames - the one my page was...
3
by: mvirta | last post by:
How can I verify that AWE is actually working? The server is SQL 2000 EE on W2KAS with the /pae switch. I've allocated 5000Mb (5Gb) for SQL but Performance monitor says the working set for the...
5
by: dBNovice | last post by:
Hi all, I am reusing code that was used in a previous copy of the DB. I am trying to extract data from other tables, queries and a form and put it in a table. The code was used previously and...
9
by: javakid | last post by:
Hi Following form validatioin code is working fine on IE but not working on Mozilla Firefox V2. Can any body suggest? Regards <script ="JAVASCRIPT" type="text/javascript">...
3
by: n.torrey.pines | last post by:
Hi I work with a nested tree-like data structure template (that happens to be a tuple of vectors of tuples of trees of something, with different tuple elements having different types) I need...
3
by: rajasree | last post by:
Hi all, am doing a project in PHP. my javascript code is working properly in ie. But its not working in firefox. Please help me my code is as follows; <script language="javascript"...
3
by: xmail123 | last post by:
Why does this code work? I am new to C# and have been studying this piece of code. It loops through an Adjacency Matrix table to populate a tree view. I have two questions about why this code...
2
by: sateeshchandrasanga | last post by:
Hi All, My HTML code is working fine in Firefox.But its not displaying any thing in IE.Can you help me in this problem.And in Google crown its displaying but not properly. ...
0
by: Barak, Ron | last post by:
Thanks Gabriel, Okay, I get it: I was under the impression that the format check would be done on the open. Bye, Ron. -----Original Message----- From: Gabriel Genellina Sent: Thursday,...
2
by: kkshansid | last post by:
i hav 2 tables 1 town containing 338 data 2 address containing 500 data i want to display town then related address then again town then related address and so on but my code not working...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.