c - Understanding the Binary Search Tree -
struct node { int key; struct node* left; struct node* right; }; struct node * newbst(int key){ struct node* temp = (struct node*) malloc(sizeof(struct node)); temp -> key = key; temp -> left = temp -> right = null; return key; }
so unable understand why malloc size of node? struct *temp ? can access elements created in node ?
to reserve memory. after struct node {...}
, have blueprint on how nodes supposed like. go urban memory planning office, , tell them "i'm making new node, can reserve 24 square meters bytes somewhere?" , tell "sure, here should place, promise not give else. make sure not mess outside 24 square meters bytes, or bad things happen". take temp
address, go there , start laying out stuff: key
goes in these 8 square meters bytes, , let's clean these 8 , these other 8 cruft may have been there before...
*) int
nowadays takes 8 bytes of memory, , each pointer well. dependent on computer , compiler.
Comments
Post a Comment