# Thread: Problem with recursive funtion

1. ## Problem with recursive funtion

Hi!

I have a problem with this recursive function. Tell me what changes variables i and j.

Code:
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <ctype.h>

# define MAX 1001

typedef struct st
{
int dat;
struct st *left;
struct st *right;
};
typedef struct st* OBST;

BST B_Tree(int i, int j)
{
OBST New = (OBST)malloc(sizeof(struct st));
int x;

if(i == j)
{
New = NULL;
return New;
}
else
{
x = r[i][j];
New->dat = keys[x];			//write key
New->right = B_Tree(x, j);	//repeat
New->left = B_Tree(i, x-1);
printf ("\ni = %d\tj = %d\tx = %d", i, j, x);
return New;
}
}
int main ()
{
OBST root;

root = B_Tree(0, 1000);
return 0;
}

2. New->right = B_Tree(x, j);
New->left = B_Tree(i, x-1);
You are calling the function here with different values.

3. Yes I know that but how are i and j variables changed. In B_Tree function there is nothing like i++ or j++ (i-- or j--) that would change the values. So please explain this to me.

4. Not sure what you mean but here

New->right = B_Tree(x, j);

you call B_Tree with a different value for i. The value for i in the new call is equal to x. And here

New->left = B_Tree(i, x-1);

The value for j in the new call is equal to x-1.