B
Bill Cunningham
I have found somecode that designs a binary search tree. Unfortunately
the compiler will not compile this saying there is a parse error before
struct on line 30. I am at a loss. I have copied this code changing only a
couple of things and I have stayed consistant.
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
int count;
};
static int find(struct node *node, int target)
{
if (node == NULL) {
return (1);
} else {
if (target == node->count) {
return (0);
} else {
if (target < node->count) {
return (find(node->right, target)
);
} else
return (find(node->left, target)
);
}
}
}
struct node *newNode(int count)
{
struct node *node = new(struct node);
Something is supposed to be wrong with the above line.
node->right = NULL;
node->left = NULL;
node->count = count;
return (node);
}
struct node *insert(struct node *node, int count)
{
if (node == NULL) {
return (newNode(count));
} else {
if (count <= node->count)
node->left = insert(node->left, count);
else
node->right = insert(node->right, count);
return (node);
}
}
the compiler will not compile this saying there is a parse error before
struct on line 30. I am at a loss. I have copied this code changing only a
couple of things and I have stayed consistant.
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
int count;
};
static int find(struct node *node, int target)
{
if (node == NULL) {
return (1);
} else {
if (target == node->count) {
return (0);
} else {
if (target < node->count) {
return (find(node->right, target)
);
} else
return (find(node->left, target)
);
}
}
}
struct node *newNode(int count)
{
struct node *node = new(struct node);
Something is supposed to be wrong with the above line.
node->right = NULL;
node->left = NULL;
node->count = count;
return (node);
}
struct node *insert(struct node *node, int count)
{
if (node == NULL) {
return (newNode(count));
} else {
if (count <= node->count)
node->left = insert(node->left, count);
else
node->right = insert(node->right, count);
return (node);
}
}