A small query really with reference to Structs.
If I had a
Struct Node {
char *number;
struct Node *next;
}List;
and a tree Structure:
struct Node {
char *name;
char *number;
struct Node *right;
struct Node *left;
};
and I wanted to design it, such that each Node within my Tree, can each contain a LIST of Phone Numbers, is there a way in which I can do this, and if so, how exactly can I reference my struct List within my Tree?
EDIT:
Any ideas as to why this is seg faulting? Using the Structs recommended below.
TreeNode* AddNode(TreeNode *root, ListNode *list, char *name, char *phonenum) {
int comparison;
if ( root == NULL ) {
root = (TreeNode *)malloc(sizeof(TreeNode));
list = (ListNode *)malloc(sizeof(ListNode));
root->name = strdup(name); root->list->number = strdup(phonenum);
root->left = root->right = NULL;
You’d simply do it like so:
Then in order to get a local copy of the first element of the list in each node, you’d do something like the following:
If you wanted to get a number that was not the first number in the list, you would have to create a search function for your linked list.