there 2 structures bst
typedef struct _price { double price; char* shopname; } pricing; typedef struct _bstnode { int id; pricing** pl; int nr_of_prices; struct _bstnode *left; struct _bstnode *right; struct _bstnode *parent; } bstnode;
i need make function can add , update price , shop name in bst node. 1 node may contain many shops , prices
void updateprice(bstnode* root, int id, char* shop, double price){ //to }
i can add single shop name , price how add several objects?
(*(root->pl))=malloc(sizeof (pricing)); // ---?? (*(root->pl))->price=price; (*(root->pl))->shopname=shop;
if nr_of_prices belongs pl, add dynamically 1 object:
int oldidx = root->nr_of_prices++; root->pl = realloc( root->pl, root->nr_of_prices * sizeof(*root->pl)); root->pl[oldidx] = malloc(sizeof(pricing)); root->pl[oldidx]->price = price; root->pl[oldidx]->shopname = shop;
Comments
Post a Comment