title: Search function for a tree
body: <p>I am working with a ternary search tree. Following code should give you an overview of how the tree looks like. Every leaf will contain a pointer to a linked list which contains pointer to the head node. Every leaf can have at most 3 nodes. Therefore after the root leaf has been filled with 3 data values the next value if it is smaller than the first node will get inserted in to the left if it is greater it gets inserted in to the right and if it is in the middle it will get inserted in to the centre child. </p>
  
  <pre><code>struct data
  {
    int val;
  };
  
  
  struct node
  {
    struct node* next;
    struct data* dta;
  };
  
  struct linkedList
  {
    int size;
    struct node *head;
  };
  
  struct leaf
  {
    struct linkedList* ll;
    struct leaf* left;
    struct leaf* right;
    struct leaf* center;
    struct leaf* parent;
  };
  
  struct tree
  {
    struct leaf* root;
  };
  </code></pre>
  
  <p>I am currently trying to create a function that takes in a tree and a int value as inputs. Then it checks every leaf in the tree to see if some leaf equals the int value and if it does it will return 1 and 0 otherwise.</p>
  
  <p><strong>Following is my code</strong></p>
  
  <pre><code>int totalLeaf(struct leaf *lf)
  {
    int sum = 0;
    struct node *temp = lf-&gt;ll-&gt;head;
    while(temp!=NULL)
    {
      sum = sum + temp-&gt;dta-&gt;val;
      temp = temp-&gt;next;
    }
    printf("sum is :  %d\n",sum);
    return sum;
  }
  
  int searchTotal(struct tree *tr,int total)
  {
    if(tr-&gt;root == NULL)
    {
      return 0;
    }
    else
    {
      return searchTotal_r(tr-&gt;root,total);
    }
  }
  
  int searchTotal_r(struct leaf *lf,int total)
  {
    if(lf==NULL)
    {
      return 0;
    }
    if(totalLeaf(lf) == total)
    {
      return 1;
    }
    else
    {
      searchTotal_r(lf-&gt;left,total);
      searchTotal_r(lf-&gt;center,total);
      searchTotal_r(lf-&gt;right,total);
    }
  
    return 0;
  }
  </code></pre>
  
  <p>Can anyone suggest where i have gone wrong and how i can fix this issue?</p>