0
#include<stdio.h>
#include<stdlib.h>

typedef struct              //create a pointer structure
{
int data;
struct node *left;
struct node *right;
} node;

node *insert(node *root, int x);

//Insert Function
node *insert(node *root, int x)    //Line 53        
{    
    if(!root)
    {
        root = new_node(x);
        return root;
    }

    if (root->data > x)
    {
        root->left = insert(root->left, x);   //Line 63
    }

    else 
    {
        root->right = insert(root->right, x);  // Line 68
    }

    return root;
}

I get the following errors while compiling:

: In function ‘insert’:

:63:3: warning: passing argument 1 of ‘insert’ from incompatible pointer type [enabled by default]

:53:7: note: expected ‘struct node *’ but argument is of type ‘struct node *’

:63:14: warning: assignment from incompatible pointer type [enabled by default]

:68:3: warning: passing argument 1 of ‘insert’ from incompatible pointer type [enabled by default]

:53:7: note: expected ‘struct node *’ but argument is of type ‘struct node *’

:68:15: warning: assignment from incompatible pointer type [enabled by default]

  1. Why is the 1st argument in my insert function incompatible with what I am passing into it?
  2. How do you assign a pointer to a 'struct pointer'?
Teddy
  • 46
  • 7

1 Answers1

0

Change the struct definition to

struct node             //create a pointer structure
{
    int data;
    struct node *left;
    struct node *right;
};

and the function prototype to

struct node *insert(struct node *root, int x);
uba
  • 2,012
  • 18
  • 21
  • What is the difference between the two styles of declaration? – Teddy Mar 08 '13 at 06:19
  • A long topic [struct vs typedef](http://stackoverflow.com/questions/1675351/typedef-struct-vs-struct-definitions) – uba Mar 08 '13 at 06:21
  • That helped a bunch! I don't think the 'shorthand' definition is the way for me. The concept of pointers and BST's are still a little fuzzy. Are there any articles that you could recommend that helped you? – Teddy Mar 08 '13 at 06:39