B
Bill Cunningham
I have found a page that more simply takes about trees but I have goofed
up here. I want to write an insert function.
#include <stdio.h>
struct node {
int data;
struct node *left, *right;
};
struct node *insert(struct node *node, int target)
{
if (node == NULL)
return 1;
else {
if (target < node->data)
printf("right");
if (target > node->data)
printf("left");
}
return 0;
}
int main()
{
struct node s;
s->data = {
1};
printf("%s\n", insert(s, 1));
}
p.c: In function `insert':
p.c:11: warning: return makes pointer from integer without a cast
p.c: In function `main':
p.c:24: invalid type argument of `->'
p.c:24: parse error before '{' token
p.c:26: incompatible type for argument 1 of `insert'
Bill
up here. I want to write an insert function.
#include <stdio.h>
struct node {
int data;
struct node *left, *right;
};
struct node *insert(struct node *node, int target)
{
if (node == NULL)
return 1;
else {
if (target < node->data)
printf("right");
if (target > node->data)
printf("left");
}
return 0;
}
int main()
{
struct node s;
s->data = {
1};
printf("%s\n", insert(s, 1));
}
p.c: In function `insert':
p.c:11: warning: return makes pointer from integer without a cast
p.c: In function `main':
p.c:24: invalid type argument of `->'
p.c:24: parse error before '{' token
p.c:26: incompatible type for argument 1 of `insert'
Bill