00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
#include "wvhashtable.h"
00015
#include "wvstring.h"
00016
#include "wvlinklist.h"
00017
#include <stdio.h>
00018
00019
00020
DeclareWvTable(
WvString);
00021
00022
00023 int ascending(
const WvString *a,
const WvString *b)
00024 {
00025
return strncasecmp(*a, *b, strlen(a->
cstr()));
00026 }
00027
00028
00029 int main()
00030 {
00031
00032
WvStringTable t(100);
00033
00034
00035
WvString s1(
"aussi"), s2(
"Bonjour"), s3(
"comment");
00036
WvString s4(
"demain"), s5(
"non"), s6(
"oui");
00037
WvString s7(
"matin"), s8(
"bonsoir"), s9(
"bien");
00038
WvString s10(
"depanneur");
00039
00040
00041
00042 t.add(&s1,
false); t.add(&s2,
false), t.add(&s3,
false);
00043 t.add(&s4,
false); t.add(&s5,
false), t.add(&s6,
false);
00044 t.add(&s7,
false); t.add(&s8,
false), t.add(&s9,
false), t.add(&s10,
false);
00045
00046
00047 printf(
"What words do we have in the dictionary?\n");
00048 WvStringTable::Iter i(t);
00049
for( i.rewind(); i.next(); )
00050 {
00051 printf(
"%s\n", i->cstr() );
00052 }
00053
00054 printf(
"There are %d words stored in the dictionary so far.\n", t.count());
00055
00056
00057
00058
00059
WvString sample1(
"Bonjour");
00060 printf(
"Is 'Bonjour' in the dictionary? %s\n", t[sample1]?
"Yes":
"No");
00061
WvString sample2(
"Salut");
00062 printf(
"Is 'Salut' in the dictionary? %s\n", t[sample2]?
"Yes":
"No");
00063
00064
00065
00066 t.remove(&s1);
00067
00068
00069 printf(
"Modified List:\n");
00070
for( i.rewind(); i.next(); )
00071 {
00072 printf(
"%s\n", i->cstr() );
00073 }
00074
00075 WvStringTable::Sorter s(t,
ascending);
00076 printf(
"Sorted modified List:\n");
00077
for( s.rewind(); s.next(); )
00078 {
00079 printf(
"%s\n", s->cstr() );
00080 }
00081
00082
00083
00084 t.zap();
00085
00086
00087 printf(
"Empty List:\n");
00088
for( i.rewind(); i.next(); )
00089 {
00090 printf(
"%s\n", i->cstr() );
00091 }
00092
00093 }
00094