diff options
Diffstat (limited to 'word.c')
-rw-r--r-- | word.c | 45 |
1 files changed, 42 insertions, 3 deletions
@@ -19,12 +19,17 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "interface.h" +#include "mainwin.h" +#include "listview.h" #include "word.h" #include "dict.h" -static inline char *wordcpy(char *word); -static inline void free_word_record(Word *record); +Word *words; +static char **sorted = NULL; + +static void sort_words(const Word *); +static inline char *wordcpy(char *); +static inline void free_word_record(Word *); int to_list(char *word) { @@ -53,6 +58,40 @@ Word *add_word_record(Word *root, char *word) return root; } +char **get_sorted() +{ + unsigned int cnt; + + cnt = get_words_count(words); + sorted = malloc(cnt*sizeof(char*)); + sort_words(words); + return (sorted - cnt); +} + +static void sort_words(const Word *root) +{ + if (root->lsibl != NULL) + sort_words(root->lsibl); + *sorted = root->word; + sorted++; + if (root->rsibl != NULL) + sort_words(root->rsibl); +} + +unsigned int get_words_count(const Word *root) +{ + unsigned int cnt = 0; + + if (root == NULL) + return 0; + else { + cnt += get_words_count(root->lsibl); + cnt += get_words_count(root->rsibl); + cnt++; + return cnt; + } +} + void free_words(Word *root) { if (root->lsibl != NULL) |