Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* *visualising recusrion*
- * ShowFun() keeps track of the recursion
- * and visualises the calls/returns
- * accordingly. You can visualise any
- * kind of recursion function, just call
- * ShowFun() with valid arguments at entry
- * and exit
- */
- #include <stdio.h>
- void ShowFun(char*,int,char);
- //test recursion function
- void f(int n) {
- //enter
- ShowFun("Enter", n, '+');
- if (n <= 0) {
- //exit-conditional
- ShowFun("Exir-Conditional", n, '-');
- return;
- }
- else {
- f(n - 1);
- f(n - 1);
- }
- //exit-default
- ShowFun("Exit-Default", n, '-');
- }
- int main()
- {
- f(3);
- return 0;
- }
- void ShowFun(char* str, int n, char op) {
- static int i = 0;
- if (op == '+') ++i;
- for (int j = 1; j < i; j++)printf("|\t");
- printf("%s f(%d): %d\n", str, n, i);
- for (int j = 1; j < i; j++)printf("|\t");
- printf("\n");
- if (op == '-') --i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement