इसलिए मैं कश्मीर एंड आर सी किताब के माध्यम से पढ़ रहा है और एक सवाल .. पेज 140-141 पर structs पर 6 अध्याय में, वहाँ कोड है कि इस तरह दिखता है है है (मैं और अधिक अप्रासंगिक भागों में से कुछ बाहर ले)
/*
the program loops through a tree looking for some word
if it finds the word itll incremenet the count by 1
if it doesnt itll add a new node
*/
struct node {
char *word;
int count;
struct node *left;
struct node *right;
}
main() {
struct node *root;
char word[1000];
root = NULL;
while(getword(word, MAXWORD) != EOF) /* getword just grabs 1 word at a time from a file of words */
if(isalpha(word[0])) /* isalpha checks to see if it is a valid word */
root = addNode(root, word);
treeprint(root); /* prints the tree */
return 0;
}
struct node *addNode(struct node *p, char *w) {
int cond;
if(p == NULL) {
p = malloc(sizeof(struct node)); /* allocates memory for the new node */
p -> word = strdup(w);
p -> count = 1;
p -> left = p -> right = NULL;
}
else if ((cond = strcmp(w, p -> word)) == 0)
p -> count++;
else if(cond < 0)
p -> left = addNode(p -> left, w);
else
p -> right = addNode(p -> right, w);
return p;
}
और मेरे भ्रम जड़ में मुख्य () फ़ंक्शन में है = addNode (रूट, शब्द)
addNode नए जोड़े गए नोड के लिए एक सूचक देता है, तो (या नोड के लिए है कि शब्द है पर अगर इसके पहले से ही वह पेड़ int), नहीं है कि पेड़ से ऊपर सभी डेटा हार? पेड़ की जड़ के रूप में ठहरने के जड़ नहीं करना चाहिए?
धन्यवाद!













