B
Bill Cunningham
In using my old cat,name,age allegory I am trying to make this tree. I
did some copying but will it work so far?
#include <stdio.h>
#include <stdlib.h>
struct tree {
char *name;
int age;
char *color;
int num;
struct tree *right, *left;
};
struct tree *insert(struct tree *tp, int v, char *c, int age, char *n)
{
if (tp) {
if (tp->num > v)
tp->left = insert(tp->left, v, *c, age, *n);
else if (tp->num < v)
tp->right = insert(tp->right, v, *c, age, *n);
} else if (tp = malloc(sizeof *tp)) {
tp->num = v;
tp->right = tp->left = NULL;
}
return tp;
}
Incomplete.
did some copying but will it work so far?
#include <stdio.h>
#include <stdlib.h>
struct tree {
char *name;
int age;
char *color;
int num;
struct tree *right, *left;
};
struct tree *insert(struct tree *tp, int v, char *c, int age, char *n)
{
if (tp) {
if (tp->num > v)
tp->left = insert(tp->left, v, *c, age, *n);
else if (tp->num < v)
tp->right = insert(tp->right, v, *c, age, *n);
} else if (tp = malloc(sizeof *tp)) {
tp->num = v;
tp->right = tp->left = NULL;
}
return tp;
}
Incomplete.