tree_t *make_empty_tree();
void insert_tree(tree_t *tree, void *name, char *movie);
void insert_node(node_t **root, node_t *new);
void traverse_tree(tree_t *tree);
static void recursive_traverse(node_t *root);
void *search_tree(tree_t *tree, void *key);
/*static void *recursive_search_tree(node_t *root, void *key);*/
void *node_search(node_t *root, void *key);
tree_t *make_empty_tree(){
tree_t *tree;
tree = malloc(sizeof(*tree));
tree->root = NULL;
return tree;
}
void insert_tree(tree_t *tree, void *name, char *movie){
int i = 0, count = 0;
node_t *new;
char *c;
new = malloc(sizeof(*new));
assert(new!=NULL);
strcpy(new->name, name);
for(i=0; i<strlen(movie); i++) {
if(isalpha(*(movie+i))){
count++;
} else if(*(movie+i) == ' ') {
count++;
}
}
c = malloc(count+1);
for(i=0; i<count; i++) {
*(c+i) = *(movie+i);
}
*(c+i) = '\0';
new->movie = malloc(count+1);
strcpy(new->movie, c);
free(c);
new->left = new->right = NULL;
insert_node(&(tree->root), new);
}
void traverse_tree(tree_t *tree){
recursive_traverse(tree->root);
}
static void recursive_traverse(node_t *root) {
if(root){
recursive_traverse(root->left);
printf(root->name);
printf("\n");
free(root->name);
free(root->movie);
free(root);
recursive_traverse(root->right);
}
}
void *search_tree(tree_t *tree, void *key){
/*return recursive_search_tree(tree->root, key); */
return node_search(tree->root, key);
}
/*static void *recursive_search_tree(node_t *root, void *key) {
int outcome;
static int comparison = 0;
if(!root) {
comparison++; printf("%s---> ", key);
printf("%d number of comparisions but NOT FOUND\n", comparison);
comparison = 0;
return NULL;
}
if ((outcome = strcmp(key, root->name))<0) {
comparison++;
return recursive_search_tree(root->left, key);
} else if (outcome > 0) {
comparison++;
return recursive_search_tree(root->right, key);
} else {
comparison++;
printf("%s---> ", key);
printf("%d number of comparisions\n", comparison);
comparison = 0;
return root->movie;
}
}*/
void *node_search(node_t *root, void *key) {
node_t** curr = &root;
int outcome;
static int comparison = 0;
while (*curr){
outcome = strcmp(key, (*curr)->name);
comparison++;
if(outcome<0) {
curr = &(*curr)->left;
} else {
if(outcome == 0){
printf("%s---> ", key);
printf("%d number of comparisions\n", comparison);
comparison=0;
return (*curr)->movie;
}
curr = &(*curr)->right;
}
}
printf("%s---> ", key);
printf("%d number of comparisions but NOT FOUND\n", comparison);
comparison = 0;
return (*curr);
}
void insert_node(node_t *(*root), node_t *new)
{
node_t** curr = root;
while (*curr)
{
if (strcmp(new->name, (*curr)->name) < 0) {
curr = &(*curr)->left;
} else {
curr = &(*curr)->right;
}
}
*curr = new;
}
我有这个treefunction.c
我试图在unix上使用vi编辑器制作makefile
它不断发出此消息
treefunction.c:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
treefunction.c:7: error: expected ')' before '*' token
treefunction.c:8: error: expected ')' before '*' token
treefunction.c:9: error: expected ')' before '*' token
treefunction.c:10: error: expected ')' before '*' token
treefunction.c:11: error: expected ')' before '*' token
treefunction.c:13: error: expected ')' before '*' token
treefunction.c:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
treefunction.c:22: error: expected ')' before '*' token
任何人都可以帮我解决这个问题
它在我的机器上编译,但在unix上它没有
我需要能够使makefile提交我的作业
任何人都可以帮助我,谢谢