i am having a normal binary tree that i am trying to apply iterative deepening depth first search on using c :
struct node {
int data;
struct node * right;
struct node * left;
};
typedef struct node node;
and i am using a function to insert nodes into tree, now i need to implement the search function to be something like this:
function search(root,goal,maxLevel)
so it search using depth first search but to a specific max level then stop
that was my first try,it doesn't work :
currentLevel = 0;
void search(node ** tree, int val, int depth)
{
if(currentLevel <= depth) {
currentLevel++;
if((*tree)->data == val)
{
printf("found , current level = %i , depth = %i", currentLevel,depth);
} else if((*tree)->left!= NULL && (*tree)->right!= NULL)
{
search(&(*tree)->left, val, depth);
search(&(*tree)->right, val, depth);
}
}
}
please help, thanks ...