Hi, I am trying to read the following information from a text file and save it a binary search tree.
The data are:
Toyota 1.3 Solid 33,235.04 3300.00
Nissan1.3 Solid 38,235.04 3300.00
struct Node
{
char model[50];
char colourType[20];
double price;
double deposit;
struct Node *parent;
struct Node *left;
struct Node *right;
};
This is my code,
void load_file()
{
char temp[2000];
char temp1[50];
char temp2[20];
double temp3;
double temp4;
struct Node *Root = NULL;
FILE*fp=fopen("class.txt", "r");
while( (fscanf(fp, "%s%s%lf%lf", temp1, temp2, &temp3, temp4))!=EOF)
{
struct Node *newNode=(struct Node*)malloc(sizeof(struct Node));
strcpy(newNode->model, temp1); // newNode->model = temp1;
strcpy(newNode->colourType, temp2); // newNode->colourType = temp2;
newNode->price = temp3;
newNode->deposit = temp4;
newNode->parent=NULL;
newNode->left=NULL;
newNode->right=NULL;
Root=Insert(Root,newNode);
}
PrintTree(Root);
return;
}
My problem is when i print out the data in my tree, the data are not print out as the sequence in the text file.
Please help me, thank you.
cjjack88