B
Bill Cunningham
I have worked with this tree function some more and I have inserted
malloc. I don't know if I'm using it right as the compiler says.
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node *right, *left;
};
static int lookup(struct node *node, int target)
{
if (node == NULL)
return 1;
else {
if (target == node->data)
return printf("data found");
else {
if (target < node->data)
return (lookup(node->left, target));
else {
return (lookup(node->right, target));
}
}
}
}
struct node *NewNode(int data)
{
struct node *node = malloc(sizeof struct node *node);
node->data = data;
node->right = NULL;
node->left = NULL;
return (node);
}
b.c: In function `NewNode':
b.c:28: parse error before "struct"
Bill
malloc. I don't know if I'm using it right as the compiler says.
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node *right, *left;
};
static int lookup(struct node *node, int target)
{
if (node == NULL)
return 1;
else {
if (target == node->data)
return printf("data found");
else {
if (target < node->data)
return (lookup(node->left, target));
else {
return (lookup(node->right, target));
}
}
}
}
struct node *NewNode(int data)
{
struct node *node = malloc(sizeof struct node *node);
node->data = data;
node->right = NULL;
node->left = NULL;
return (node);
}
b.c: In function `NewNode':
b.c:28: parse error before "struct"
Bill