Bill asked:
> Does this complete the tree or node structure?

K&R use typedefs to tidy things up:


typedef struct tnode *Treeptr;

typedef struct tnode {  /* the tree node */
  char *word;  /* points to the text */
  int count;  /* number of occurrences */
  Treeptr left;  /* left child */
  Treeptr right;  /* right child */
} Treenode;

Treeptr talloc(void)
{
  return (Treeptr) malloc(sizof(Treenode));
}


This code is used to build a tree of words from a text, 
including the number of times each word occurs. The talloc() 
function allocates memory for a new node. Without typedefs, 
it's a bit messier:


struct tnode *talloc(void)
{
  return (struct tnode *) malloc (sizeof(struct tnode));
}

(Apologies for any typos I haven't spotted.)

David

Reply via email to