Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. BST* addWord(BST* node, char* tword, int x){
  2.   if(node == NULL){
  3.     node = (BST*) malloc(sizeof(BST));
  4.     //memset(node, NULL, sizeof(BST));
  5.     node->word = tword;
  6.     node->count = 1;
  7.     node->left = node->right = NULL;
  8.     ListItem* p = NULL;
  9.     p = (ListItem*) malloc(sizeof(ListItem));
  10.     memset(p, NULL, sizeof(ListItem));
  11.     p->value = x;
  12.     node->pHead = p;
  13.     node->pTail = p;
  14.     return node;
  15.   }
  16.  
  17.   int cmp = stricmp( tword, node->word );
  18.  
  19.   if( cmp  < 0 ){
  20.     node->left = addWord(node->left, tword, x);
  21.   }else if( cmp > 0 ){
  22.     node->right = addWord(node->right, tword, x);
  23.   }else{
  24.     addToList( &(node->pTail), x);
  25.     (node->count)++;
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement