B
Bill Cunningham
Structs with pointers and members not involving members are easy in C.
But with trees I ask why are pointers preferred and recursion is a little
confusing. I have this code:
#include <stdio.h>
struct tree {
char *name;
char *color;
};
int main() {
struct tree p;
struct tree *pt=&p;
pt->name="striper";
pt->color="mau";
printf("%s %s\n",pt->name,pt->color);
return 0;
}
When prints out name and color of cat. but the step I am missing is the
memory allocation (malloc()) and members that are called *left and *right
nodes. I understand there is a root node and a node that is copied from
that. Then several right and left nodes with a BST. How do I allocate memory
using this?
Bill
But with trees I ask why are pointers preferred and recursion is a little
confusing. I have this code:
#include <stdio.h>
struct tree {
char *name;
char *color;
};
int main() {
struct tree p;
struct tree *pt=&p;
pt->name="striper";
pt->color="mau";
printf("%s %s\n",pt->name,pt->color);
return 0;
}
When prints out name and color of cat. but the step I am missing is the
memory allocation (malloc()) and members that are called *left and *right
nodes. I understand there is a root node and a node that is copied from
that. Then several right and left nodes with a BST. How do I allocate memory
using this?
Bill