Page 173 - ARM 64 Bit Assembly Language
P. 173

160 Chapter 6


                13  /* wl_free frees all the storage used by a wordlist   */
                14  void wl_free(wordlist* wl);
                15
                16  /**********************************************************/
                17  /* wl_increment adds one to the count of the given word.  */
                18  /* If the word is not in the list, then it is added with  */
                19  /* a count of one.                                    */
                20  void wl_increment(wordlist *list, char *word);
                21
                22  /**********************************************************/
                23  /* wl_print prints a table showing the number         */
                24  /* of occurrences for each word, followed by the word.  */
                25  void wl_print(wordlist *list);
                26
                27  /**********************************************************/
                28  /* wl_print_numerical prints a table showing the number  */
                29  /* of occurrences for each word, followed by the word,  */
                30  /* sorted in reverse order of occurence.              */
                31  void wl_print_numerical(wordlist *list);
                32
                33  #endif

                                    Listing 6.6 C implementation of the wordlist ADT.

                1  #include <stdlib.h>
                2  #include <string.h>
                3  #include <stdio.h>
                4  #include <list.h>
                5
                6  /**********************************************************/
                7  /* The wordlistnode type is a linked list of words and  */
                8  /* the number of times each word has occurred.         */
                9  typedef struct wlist_node{
                10  char *word;
                11  int count;
                12  struct wlist_node *next;
                13  }wordlistnode;
                14
                15  /**********************************************************/
                16  /* The wordlist type holds a pointer to the linked list  */
                17  /* and keeps track of the number of nodes in the list  */
                18  typedef struct wlist{
                19  int nwords;
                20  wordlistnode *head;
                21  }wordlist;
                22
                23  /**********************************************************/
                24  /* wl_alloc allocates and initializes a new word list.  */
                25  wordlist* wl_alloc()
   168   169   170   171   172   173   174   175   176   177   178