hello when i try to run this code i'm gettin an error
"undefined reference to 'insert'
pleaze someone help me
this is the code
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct pbentry {
char nom[30];
char prenom[30];
int numero;
float moyenne;
} Entry;
/*Create tree node structure.*/
struct tree_node {
Entry data;
struct tree_node *left;
struct tree_node *right;
};
struct tree_node * insert(struct tree_node *p, Entry e);
struct tree_node * create_node (struct tree_node *q, struct tree_node *r, Entry e);
int main(void)
{
int option = 0; /*Variable for option selection.*/
Entry e; /*Basic entry*/
struct tree_node *p = NULL; /*Basic tree node*/
char ln[16]; /*Used for deletions, editing, and searching*/
char fn[11]; /*Used for deletions, editing, and searching*/
/*Return to menu after each instruction until the user quits.*/
while (option != 6) {
/*Show user the option menu.*/
printf("MENU\n");
printf("1. Add\n");
printf("2. Delete\n");
printf("3. Edit\n");
printf("4. Search\n");
printf("5. List\n");
printf("6. Quit\n");
/*Get option from the user.*/
printf("\nPlease select an option: ");
scanf("%d", &option);
/*If option is 1 (Add):*/
if (option == 1) {
/*Take in subject data from the user.*/
printf("Ajouter le n: ");
scanf("%s", &e.numero);
printf("Ajouter le nom ");
scanf("%s", &e.nom);
printf("Ajouter le prenom ");
scanf("%s", &e.prenom);
printf("Ajouter la moyenne ");
scanf("%s", &e.moyenne);
/*Create a new node.*/
p = insert(p, e);
/*Confirm node creation.*/
printf("Record added successfully.\n\n");
}
/*Adds a node to the tree.*/
struct tree_node * insert(struct tree_node *p, Entry e){
if (p == NULL) {
p = create_node(NULL, NULL, e);
}
else if (e.numero < p->data.numero) {
p->left = insert(p->left, e);
}
else if (e.numero > p->data.numero) {
p->right = insert(p->right, e);
}
else {
return p;
}
}
return p;
}
/*Creates a new node.*/
struct tree_node * create_node (struct tree_node *q, struct tree_node *r, Entry e) {
struct tree_node* newnode;
newnode = (struct tree_node*)(malloc(sizeof(struct tree_node)));
newnode->data = e;
newnode->left = q;
newnode->right = r;
return newnode;
}
}