summaryrefslogtreecommitdiff
path: root/word.c
diff options
context:
space:
mode:
authorb0ric <b0risov.alexandr@rambler.ru>2009-08-08 20:18:38 +0300
committerb0ric <b0risov.alexandr@rambler.ru>2009-08-08 20:18:38 +0300
commit343357ed1e7907cf4b488058053df280ae63c7bb (patch)
tree201915ed25612180af3745131be66ce19edf1a0b /word.c
parent88db5cdceabf042f5e5d5695bf984900f8396225 (diff)
Now words are shown in alphabetical order
Diffstat (limited to 'word.c')
-rw-r--r--word.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/word.c b/word.c
index 25d4ff1..9f16695 100644
--- a/word.c
+++ b/word.c
@@ -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)