'Working with linked list whose member is a binary search tree (BST)
I am new to C data structures and I am working with a linked list and a binary search tree. The linked list is composed of 2 members, a string type and a binary search tree type. Here is its definition:
typedef char *String;
struct LinkedList
{
int employer_id;
EmployeeBST employees;
struct LinkedList *next;
} *LinkedList;
struct list
{
ListNodePtr head;
} EmployeeList;
The employee BST definition on the other hand
typedef char *String;
typedef struct bstNode
{
String employeeName;
struct bstNode *left;
struct bstNode *right;
} *BSTNodePtr;
typedef struct bst
{
BSTNodePtr root;
} EmployeeBST;
I want to insert new members to the linked list, here is my insert function
struct listNode *newListNode(String unit_code, EmployeeBST employees)
{
struct listNode *newNode;
newNode = malloc(sizeof(struct listNode));
newNode->employer_id = 89;
newNode->employees;
}
The problem is what value should I assign to the newMode->employees? I have the insert function for the BST which is implemented as:
struct bstNode *insert(struct bstNode *bstNode, int employer_id)
{
if(bstNode == NULL)
{
return newBstNode(employer_id);
}
// traverse right and insert the node
if(employer_id < bstNode->employer_id)
{
bstNode->left = insert(bstNode->left, employer_id);
}else
{
bstNode->right = insert(bstNode->right, employer_id);
}
return bstNode;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
