Page 185 - ARM 64 Bit Assembly Language
P. 185

172 Chapter 6


               155            if(strcmp(node->word,root->right->word) >= 0)
               156              root = wln_rotate_left(root);
               157            else
               158              {
               159                root->right = wln_rotate_right(root->right);
               160                root = wln_rotate_left(root);
               161              }
               162          }
               163    }
               164  return root;
               165  }
               166
               167  /**********************************************************/
               168  /* The wordlist type holds a pointer to the binary tree  */
               169  /* and keeps track of the number of nodes in the list  */
               170  typedef struct wlist{
               171  int nwords;
               172  wordlistnode *root;
               173  }wordlist;
               174
               175  /**********************************************************/
               176  /* wl_alloc allocates and initializes a new word list.  */
               177  wordlist* wl_alloc()
               178  { wordlist* tmp;
               179  tmp = (wordlist*)malloc(sizeof(wordlist));
               180  if(tmp == NULL)
               181    {
               182      printf("Unable to allocate wordlist\n");
               183      exit(1);
               184    }
               185  tmp->nwords = 0;
               186  tmp->root = NULL;
               187  return tmp;
               188  }
               189
               190  /**********************************************************/
               191  /* wl_free frees all the storage used by a wordlist   */
               192  void wl_free(wordlist* wl)
               193  {
               194  wln_free(wl->root);
               195  free(wl);
               196  }
               197
               198  /**********************************************************/
               199  /* wl_increment adds one to the count of the given word.  */
               200  /* If the word is not in the list, then it is added with  */
               201  /* a count of one.                                    */
               202  void wl_increment(wordlist *list, char *word)
               203  {
   180   181   182   183   184   185   186   187   188   189   190