Talk:Binary search tree (C)
From LiteratePrograms
struct bst_node {
void* data;
struct bst_node* left;
struct bst_node* right;
};
<<declarations>>=
struct bst_node* new_node(void* data);
Hi to everyone, i've one question to u buddies that i'm not getting the above coding.Please explain the above lines in some detils...........Thanks u
- I've taken the liberty to fix the Wiki formatting for you (i.e. I added <codeblock> tags).
- Well, the "<<declarations>>=" is part of the literateprograms wiki markup. It just means what follows belongs into the chunk "declarations". See LiteratePrograms:How to write an article to learn more about that.
- The rest ist just standard C. The part before "<<declarations>>=" defines a struct type (i.e. a type consisting of several named fields) with name bst_node. A struct bst_node consists of a pointer to void names data, and two pointers to struct bst_node, named left and right. The first one obviously will point to the data held by the node, while left and right will point to the left and right sub-trees.
- The part after "<<declarations>>=" is the declaration of a function taking a pointer to void, and returning a pointer to struct bst_node. The name suggests that the returned value points to a new object of type struct bst_node, which looking at the code confirms.
- I suggest you read a good book about C. OTOH, looking at the article I think a bit mopre explanation would be in order there as well (while explaining C constructs is IMHO outside the scope of the article, it should have a better documentation/explanation of the code). I'm going to improve that a bit.
- BTW, please sign your contributions (i.e. add --~~~~ at the end). --Ce 11:18, 14 April 2007 (PDT)
- Possible bug in the delete code? When deleting the inorder predecessor, what about setting its parent's right pointer to null? (RF)
