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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -