I have this assignment for my Algorithms class to write a system for a car dealership that allows them to search through their inventory so that the complexity of the search is not O(n). To solve this I chose to use a binary search tree that points to the different models of cars and then using three different BSTs to allow for searches of each model for price, mileage and year.
The BSTs are built using an array implementation, where the left child of a parent is 2* the parent index + 1, and the right child is 2* the parent index + 2.
the three structures I am using are defined as such:
typedef struct car {
int inventoryID;
char* make;
char* model;
int year;
int mileage;
int price;
} car;
typedef struct car_BST {
car (**cars)[3];
int size;
} car_BST;
typedef struct BST {
car_BST** carModel;
int size;
} BST;
So when I try to add a car to each tree i follow this general step by step process:
while(1){
if (tmp->cars[val][i[val]] == NULL){
tmp->cars[val][i[val]] = newCar;
break;
}
if (i[val] > tmp->size)
incrCar_BSTSize(tmp, i[val]);
if (newCar->price >= tmp->cars[val][i[val]]->price)
i[val] = 2 * i[val] + 2;
else
i[val] = 2 * i[val] + 1;
}
Yet the compiler reports an error that says "assignment to expression with array type"
Is there something obvious that I have missed or am I just doing something fundamentally wrong?