-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
41 lines (33 loc) · 848 Bytes
/
Copy pathmain.c
File metadata and controls
41 lines (33 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "lab13.h"
int main(void) {
int size;
FILE *fp = fopen("C_BinrarySearchTree/employee.csv", "r"); // open file
if (fp){
fscanf(fp,"%d\n", &size);
}
else {
printf("Cannot find the file\n"); // error checking
return -1;
}
Employee** array = (Employee**)malloc(sizeof(Employee*)*size);
if (array == NULL){ // error check for malloc
printf("Allocating memory failed\n");
return -1;
}
// read data into array
for (int i = 0; i < size; i++){
array[i] = readRecord(fp);
}
fclose(fp);
Node* BST = NULL;
for (int i = 0; i < size; i++){
BST = insertBST(BST,(void*)array[i]);
}
inOrderPrintAge(BST);
deleteTree(BST);
for (int i = 0; i < size; i++){
free(array[i]);
}
free(array);
return 0;
}